Editor.getSelected() 给了我未定义的状态。
你可以先检查'component.getTrait('href')'是否能获得什么: “''js editor.on('component:selected', component => { component.getTrait('href') && component.getTrait('href').set('options', data.list); }); ```
阅读下方完整回答 ↓问题
你好@artf我想在特定的链接特征上添加动态页面。 这是我用的。 'const component = editor.getSelected(); component.getTrait('link').set('options', [ { 值: 'opt1', name: 'New option 1'}, { value: 'opt2', name: 'New option 2'}, ]); ` 这导致控制台中组件未定义,因为默认情况下没有选择任何元素 你能帮我指点一下吗?我想在点击链接时把那个页面附加到链接特征列表里
回答(3)
你可以先检查'component.getTrait('href')'是否能获得什么:
“''js editor.on('component:selected', component => { component.getTrait('href') && component.getTrait('href').set('options', data.list); });
非常感谢@Ju99ernaut 现在,它运行得非常完美。 非常感谢你的帮助。 结束这个问题。
你可以用以下方法为每种组件类型添加: “''js const components = 编辑器。Components.getTypes(); components.forEach(component => { 操控这里的特质...... });
相关问答
通过相似的问题讨论继续研究。
问题 #3247
问题:性状
你好@artf——你建造的东西非常壮观。这过程很温和,因为我远非JS高手。不过,我几乎所有配置都完成了——除了这个! 我想设置在选择图片时显示的特征(alt、src、id)。我相信初始化时可以完成一次,但我真不知道怎么做。我已经读遍了所有能找到的相关内容,但仍然卡住了。 我唯一...
问题 #3404
风格管理器问题。
你好@artf我想隐藏和显示特定组件的样式属性。 提到这个问题后,我就说 https://github.com/artf/grapesjs/issues/1428 我用这个方法写代码,但出现了错误 -: “''js 导出默认值(编辑器,配置)=> { const sm = 编辑...
问题 #3329
我应该如何在脚本中获得自定义特质修改?
你好,@artf,这是一个很棒的框架,非常感谢。 我现在用它来创建移动版 BUI 框架的组件,遇到了一个问题,我添加了自定义的特性文本区,我该如何制作这个?当数据发生变化时,它会在输出脚本中触发。 “''js 编辑。TraitManager.addType('textarea'...
问题 #2716
在Grapejs中添加自定义字体的问题
@artf 我按照下面的方法成功添加了列表中的字体,但并非所有字体都显示正确行为,我想在系统中添加Avenir字体,添加时并没有把字体改成Avenir,而是给了某个默认值 editor.on('load', function () { styleManager = 编辑器。风格...
与此问题匹配的付费插件
根据问题关键词和标签相关性精选,助你更快交付。
正在加载付费插件推荐……
相关教程
关于同一主题的深入指南。
教程
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
教程
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.
教程
How to Build a GrapesJS Plugin From Scratch Using GrapesJS CLI
Step-by-step tutorial on creating a GrapesJS plugin with CLI. Scaffold, develop, test, and publish plugins easily with this complete guide
浏览插件分类
直接跳转到市场上的插件分类页面。