Javascript ckeditor-如何管理配置更改
我有一个依赖于一些自定义参数的ckeditor插件。这些参数可能会在操作过程中改变值。我最终实现这一点的方式是将当前值保存在插件内部的局部变量中,插件在开始时初始化,可以通过自定义命令进行更改。像这样Javascript ckeditor-如何管理配置更改,javascript,ckeditor,Javascript,Ckeditor,我有一个依赖于一些自定义参数的ckeditor插件。这些参数可能会在操作过程中改变值。我最终实现这一点的方式是将当前值保存在插件内部的局部变量中,插件在开始时初始化,可以通过自定义命令进行更改。像这样 var somethingId = editor.config.myplugin_Something; editor.addCommand('changeSomething', { exec: function(_editor, data) { somethingId =
var somethingId = editor.config.myplugin_Something;
editor.addCommand('changeSomething', {
exec: function(_editor, data) {
somethingId = data.something;
}
});
这工作正常,但我遇到了一个问题(据我所知),我正在达到需要更改数据的情况,但编辑器尚未初始化,所以请致电
$.each(CKEDITOR.instances, function (index, editor) {
editor.execCommand('changeSomething', {
something: newValue
});
});
没有效果,插件以初始配置中传递的值结束
除了使用全局变量,我想不出一个好办法。有没有更好的方法来管理ckeditor插件的可变配置参数?我想出了一个足够简单的解决方案。使用
config
对象本身,并确保初始化回调也设置了正确的值
因此,初始化看起来更像:
var config = { width: xxx, height: xxx}; // do not include "something" value
$('#mytextbox').ckeditor(function(){
this.config.myplugin_somethingId = currentSomethingValue;
});
以后需要修改的时候我会
$.each(CKEDITOR.instances, function (index, editor) {
editor.config.myplugin_somethingId = newSomethingValue;
});