更改 CKEditor 实例的配置选项
我有一个附加到 textarea
的 CKEditor 实例。我希望能够在创建后更改该实例的一些配置选项,具体取决于另一个表单字段的值。
是否可以执行此操作,否则有必要销毁该实例并使用新选项附加另一个实例?我已经检查了 CKEditor 文档,但没有发现任何有关此主题的信息。
提前致谢,
I have a CKEditor instance attached to a textarea
. I would like to be able change some configuration options of this instance after its creation, depending on the value of another form field.
Is it possible to do this, or else it's necessary to destroy the instance and attach another one, with the new options? I've checked in the CKEditor docs, but found nothing about this subject.
Thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常配置选项仅在创建时才起作用。您也许可以执行一些技巧,以便稍后获得一些可以使用的选项,但这通常会更困难。
Usually the configuration options will work only upon creation. You might be able to perform some tricks and so get some of the options to work at a later time, but that's usually more difficult.
我知道我迟到了。但我想分享这一点。
如果您在创建 ckeditor 实例之前决定配置并计划覆盖这些配置,则这是不可能的。您绝对可以添加更多配置选项,但不能更改任何现有选项。
假设您在创建实例时传递配置对象。
CKEDITOR 将在内部调用替换函数来创建实例。反过来,它将检查 config.js 中是否存在任何内容。
您提供一些额外的配置选项,并且尝试覆盖任何现有选项,例如工具栏。
在内部,CKEDITOR 将进行扩展,并尝试合并现有的配置对象和 config.js 提供的新配置对象,最后创建一个新的配置对象,用于创建实例。
当它扩展时,即尝试合并两个配置对象,它将采用所有新的配置选项并分配给最终的新配置对象。但是,对于您尝试在 config.js 中覆盖的现有配置选项,它将采用原始选项并分配给这个新的配置对象。
因此,您提供的用于覆盖现有配置对象的任何内容都会丢失。
您可以选择的一种选择是销毁当前实例并使用新的配置对象来创建实例。
我希望我能够解释一下。
I know I am late. But I would like to share this.
If you decide on a config before the creation of a ckeditor instance and plan on overriding those configurations, it's not possible. You can definitely add more config options but cannot change any existing option.
Say you pass a config object while creation of an instance.
CKEDITOR will internally call replace function to create the instance. Which will, in turn, check if anything is present in config.js.
You provide some extra config option and also, you try to override any existing option, for eg., toolbar.
Internally, CKEDITOR will do an extend and will try to merge already existing config object and the new config object provided by config.js and finally create a new config object which it will use to create the instance.
When it extends, i.e tries to merge both the config object, it will take all the new config options and assign to final new config object. But, for existing config options which you tried to override in config.js, it will take the original option and assign to this new config object.
Hence, whatever you had provided to override existing config object is lost.
One option which you have is to destroy the current instance and use your new config object to create the instance.
I hope I was able to explain.