如何动态更新下拉菜单中的项目?是否可以重新初始化CKEditor组合框/下拉菜单?
我有一个CKEditor自定义插件,它可以填充一个下拉菜单,其中列出了我可以注入到textarea
中的项目。
这个项目列表来自一个名为maptags
的Javascript数组,它为每个页面动态更新。
var maptags = []
的标签这份名单被添加到下拉当你第一次点击它由init:
功能。我的问题是,如果该数组中的项目随着客户端更改页面上的内容而发生变化,那么如何将该列表重新加载到更新的数组中?
这里是我的CKEditor插件代码:
CKEDITOR.plugins.add('mapitems', {
requires: ['richcombo'], //, 'styles' ],
init: function (editor) {
var config = editor.config,
lang = editor.lang.format;
editor.ui.addRichCombo('mapitems',
{
label: "Map Items",
title: "Map Items",
voiceLabel: "Map Items",
className: 'cke_format',
multiSelect: false,
panel:
{
css: [config.contentsCss, CKEDITOR.getUrl(editor.skinPath + 'editor.css')],
voiceLabel: lang.panelVoiceLabel
},
init: function() {
this.startGroup("Map Items");
//this.add('value', 'drop_text', 'drop_label');
for (var this_tag in maptags) {
this.add(maptags[this_tag][0], maptags[this_tag][1], maptags[this_tag][2]);
}
},
onClick: function (value) {
editor.focus();
editor.fire('saveSnapshot');
editor.insertHtml(value);
editor.fire('saveSnapshot');
}
});
}
});
这个解决方案正常工作与静态数据,但是当我尝试使用从服务器获取数据的上述解决方案,它显示为空白。你能帮我吗? –
从服务器获取您的物品从Ajax调用并将它们放在“yourListOfItems”数组中 –
这有点混乱,但它让我走上了正确的轨道。谢谢!附: richCombo对象的结构很奇怪而且很糟糕,而且这种能力真的应该是richCombo的一部分,而不必从外部入侵它。 –