我应该如何在脚本中获得自定义特质修改?
你需要在“剧本道具”中添加这个特质,你可以在这里阅读更多内容 https://grapesjs.com/docs/modules/Components-js.html#passing-properties-to-scripts
阅读下方完整回答 ↓问题
你好,@artf,这是一个很棒的框架,非常感谢。 我现在用它来创建移动版 BUI 框架的组件,遇到了一个问题,我添加了自定义的特性文本区,我该如何制作这个?当数据发生变化时,它会在输出脚本中触发。 “''js 编辑。TraitManager.addType('textarea', { createInput({ 特质, 组成部分 }) { 这里我们可以决定使用性状中的性质 const el=document.createElement('div'); el.innerHTML = ' <textarea class=“buiv-textarea” name=“${options[0].name}” rows=“${options[0].rows}”>${options[0].value}</textarea> ; 返回EL; }, onEvent({ elInput, 组成部分, 活动 }) { 数据变更会到达这个回调,你可以操作组件,但我们如何触发脚本中接收到的参数? }, onUpdate({ elInput, 组成部分, 特征 }) { }, }); 使用特征文本区 编辑。DomComponents.addType(“slide”, { model: defaultModel.extend({ 默认值:{ ...defaultModel.prototype.defaults...
回答(4)
你需要在“剧本道具”中添加这个特质,你可以在这里阅读更多内容 https://grapesjs.com/docs/modules/Components-js.html#passing-properties-to-scripts
谢谢@Ju99ernaut,如果是某些内置功能,修改脚本时可以接收参数值,我目前遇到问题:自定义功能“textarea”可以触发DOM等更改,但导出脚本无法接收该参数的值,即使脚本道具设置为“datas”。
你可以尝试强制脚本更新:
“''js 编辑。DomComponents.addType('slide', { 型号:{ // ... init() { this.on('change:datas', () => this.trigger('change:script')); }, }, // ... });
谢谢你举报,@imouou。 关于我应该如何在脚本中获得自定义特质修改?的好问题。推荐的 Canvas 方法是使用事件驱动的 API。 从这里开始: 查看你所在模块的[GrapesJS文档](https://grapesjs.com/docs/) 寻找“on()”事件监听器方法 大多数操作可以通过监听编辑器和组件事件来实现 常见模式: “JavaScript 留意变化 editor.on('change', () => console.log('something changed')); 组件生命周期 editor.on('component:mount', (c) => console.l...
相关问答
通过相似的问题讨论继续研究。
问题 #5352
未捕获的语法错误:意外令牌 '{',时间为CanvasView.ts:590:12
葡萄JS版本 [X] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? 版本 1.56.20 Chromium:115.0.5790.171(Offizieller 构建)(arm64) 可复制演示链接 没有 描述一下那个虫子 我有一个带有脚本的组件类型 在使用此类组...
问题 #3342
组件脚本中的 jQuery 无法正常工作
嗨! 我尝试过在Canvas和index.html中添加jQuery。 我正在这样用canvas添加它—— 'canvas = 编辑。画布; const script1 = document.createElement('script'); script1.src = 'htt...
问题 #5141
组件在更新性状时重置属性值(仅首次)
葡萄JS版本 [X] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? Chrome 版本 113.0.5672.63 可复制演示链接 https://jsfiddle.net/rajevar/zLs8q97f/4/ 描述一下那个虫子 这是针对这次讨论 https:/...
问题 #3694
问题:动态变更在从数据库加载时消失
@artf 这是我的代码,我在 select change 时在 div 里添加 test init() { this.listenTo(this,“change:noOfLinks”,this.getInfoLinks); }, getInfoLinks() { let ca...
与此问题匹配的付费插件
根据问题关键词和标签相关性精选,助你更快交付。
正在加载付费插件推荐……
相关教程
关于同一主题的深入指南。
教程
Vanilla GrapesJS vs GrapesJS With Plugins: What You Actually Get Out of the Box (2026)
New to GrapesJS? See exactly what the stock editor gives you, where it falls short, and which plugins close the gaps — a beginner-friendly 2026 comparison
教程
Lighthouse for GrapesJS: Audit Accessibility and SEO Without Leaving the Editor
Live WCAG 2.1/2.2 accessibility auditor + SEO manager for GrapesJS. Every finding is bound to the exact component — click to select, then one-click fix.
教程
GrapesJS DevTools: A Developer Panel Inside Your Editor
If you've ever debugged GrapesJS with console.log(editor.getSelected()) and a dozen throwaway event listeners — this post is for you.
浏览插件分类
直接跳转到市场上的插件分类页面。