集合内容函数会清空组件内容
问题
我正在尝试用 set 函数来更改组件的内容,但实际上结果是一个空组件,内部什么都没有。
这是一个代码总结的示例
editor.on('component:selected', () => {
const selectedComponent = editor.getSelected()
selectComponent.set('content', “foo”)
});
使用版本:0.16.44
预期的行为是什么?
执行的代码应生成一个包含文本“foo”的组件。
目前的行为是什么? 执行后的代码会清空组件内容。
在0.16.34版本中,一切正常运行。
这个问题有解决办法吗,还是我应该继续用0.16.34版本?
回答(2)
你不应该使用“content”属性,应该用“selectedComponent.components(str)”。
谢谢你举报,@nairdapuiu。 关于Set content function清空组件内容,这个问题很棒。推荐的组件方法是使用事件驱动的API。 从这里开始: 查看你所在模块的[GrapesJS文档](https://grapesjs.com/docs/) 寻找“on()”事件监听器方法 大多数操作可以通过监听编辑器和组件事件来实现 常见模式: “JavaScript 留意变化 editor.on('change', () => console.log('something changed')); 组件生命周期 editor.on('component:mount', (c) => co...
相关问答
通过相似的问题讨论继续研究。
问题 #6250
克隆页面提示“将循环结构转换为 JSON”
葡萄JS版本[X] 我确认使用最新版本的GrapesJS你用的是什么浏览器? Chrome 129.0.6668.101可复制演示链接 https://grapesjs.com/demo描述一下那个虫子 如何复现这个漏洞? 开放 https://grapesjs.com/dem...
问题 #5175
移动方法没有按预期工作
葡萄JS版本 [X] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? 铬 可复制演示链接 https://codesandbox.io/s/adoring-margulis-873kdv 描述一下那个虫子 背景 移动组件的方法没有按预期工作。 这段代码没有按预期工作...
问题 #5503
ReplaceWith 方法没有字符串类型
葡萄JS版本 [X] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? 铬 可复制演示链接 没有 描述一下那个虫子 Component.ts 的 replaceWith 方法没有字符串类型。 预期的行为是什么? 我应该可以用字符串替换组件,比如示例中的“compone...
问题 #3688
如何自定义组件
我 https://grapesjs.com/docs/modules/Components.html#define-custom-component-type 读了这份文档,并尝试编写以下代码。我想让“mj-body”无法删除: 但我看不到效果,请帮帮我
与此问题匹配的付费插件
根据问题关键词和标签相关性精选,助你更快交付。
正在加载付费插件推荐……
相关教程
关于同一主题的深入指南。
教程
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 Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
教程
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins — TinyMCE Inline Text Editor and Placeholder.
浏览插件分类
直接跳转到市场上的插件分类页面。