从没有名称和 ID 值的元素分离 CK 编辑器
Detaching CK Editor from an element with no name and Id value
我正在开发一个 CMS,其中的元素是动态创建的,有些元素是预加载的,我需要将 CK 编辑器从那些预加载的元素中分离出来,然后再次将 CK 编辑器附加到目标区域中的所有可编辑元素,包括预加载的元素一个。
I'm in this loop, that gives me the target div being appended and I need to remove the CK Editor from the preloaded elements with CK Editor without knowing their Ids and name values.
//here 'thisElement' is the array of all editable elements being appended including preloaded ones
var i;
for (i = 0; i < thisElement.length; i++) {
//something like this, this doesn't work
// CKEDITOR.destroy(thisElement.get(a));
//or something like this, this doesn't work
// CKEDITOR.editable(thisElement.get(i));
CKEDITOR.inline(thisElement.get(i));
for (name in CKEDITOR.instances) {
delete CKEDITOR.instances[name];
}
};
我怎样才能做到这一点?
我也在做类似的事情。我在 table 中添加和删除行,谁的条目绑定到一个集合。因此,我必须重新播种 DOM 中的索引,并删除并重新附加我所有的 CKEditors。
以下是对我有用的方法,但它确实从当前页面中删除了所有编辑器。
EDIT:添加检查以查看 CKEditor 名称是否在 DOM 元素名称的数组中。
var domElements = ["element1", "element2"];
for (instance in CKEDITOR.instances) {
if (CKEDITOR.instances.hasOwnProperty(instance)) {
if (jQuery.inArray(CKEDITOR.instances[instance].name, domElements) !== -1) {
CKEDITOR.instances[instance].destroy();
}
}
}
希望对您有所帮助
我正在开发一个 CMS,其中的元素是动态创建的,有些元素是预加载的,我需要将 CK 编辑器从那些预加载的元素中分离出来,然后再次将 CK 编辑器附加到目标区域中的所有可编辑元素,包括预加载的元素一个。
I'm in this loop, that gives me the target div being appended and I need to remove the CK Editor from the preloaded elements with CK Editor without knowing their Ids and name values.
//here 'thisElement' is the array of all editable elements being appended including preloaded ones
var i;
for (i = 0; i < thisElement.length; i++) {
//something like this, this doesn't work
// CKEDITOR.destroy(thisElement.get(a));
//or something like this, this doesn't work
// CKEDITOR.editable(thisElement.get(i));
CKEDITOR.inline(thisElement.get(i));
for (name in CKEDITOR.instances) {
delete CKEDITOR.instances[name];
}
};
我怎样才能做到这一点?
我也在做类似的事情。我在 table 中添加和删除行,谁的条目绑定到一个集合。因此,我必须重新播种 DOM 中的索引,并删除并重新附加我所有的 CKEditors。
以下是对我有用的方法,但它确实从当前页面中删除了所有编辑器。
EDIT:添加检查以查看 CKEditor 名称是否在 DOM 元素名称的数组中。
var domElements = ["element1", "element2"];
for (instance in CKEDITOR.instances) {
if (CKEDITOR.instances.hasOwnProperty(instance)) {
if (jQuery.inArray(CKEDITOR.instances[instance].name, domElements) !== -1) {
CKEDITOR.instances[instance].destroy();
}
}
}
希望对您有所帮助