tinymce 中的动态项目菜单
Dynamic items menu in tinymce
我的菜单必须根据上下文更改:
editor.addMenuItem('table_entity', {
context : 'contextmenu',
text : 'Table Entity',
icon : false,
onPostRender: function () {
var menu = this;
editor.on('NodeChange', function (e) {
var table = editor.dom.getParent(e.element, 'table');
if (table === null || table.classList.value.search(/prefix_/) == -1) {
menu.disabled(true);
menu.settings.menu = null;
} else {
var match = table.classList.value.match(/prefix_(.+)\s|$/);
if (match[1] !== undefined) {
menu.settings.menu = firstItem(match[1]).concat(self.getMenu(match[1], self[match[1] + 'Property']));
menu.disabled(false);
}
}
})
}
});
,但它不起作用。对象中的数据已更改 (menu.settings.menu),当 menu.disabled(true) 时 - 一切正常,但在其他情况下,我看到第一次生成的菜单项(即对象中的数据正在更改,下拉菜单中的项目不变)。
TinyMCE 不支持在编辑器初始化后动态添加项目到菜单。如果你必须这样做,你可以
- 先全部添加,然后 enable/disable 根据需要添加
- 用户
remove()
和 init()
使用不同的菜单选项重新初始化编辑器
我的菜单必须根据上下文更改:
editor.addMenuItem('table_entity', {
context : 'contextmenu',
text : 'Table Entity',
icon : false,
onPostRender: function () {
var menu = this;
editor.on('NodeChange', function (e) {
var table = editor.dom.getParent(e.element, 'table');
if (table === null || table.classList.value.search(/prefix_/) == -1) {
menu.disabled(true);
menu.settings.menu = null;
} else {
var match = table.classList.value.match(/prefix_(.+)\s|$/);
if (match[1] !== undefined) {
menu.settings.menu = firstItem(match[1]).concat(self.getMenu(match[1], self[match[1] + 'Property']));
menu.disabled(false);
}
}
})
}
});
,但它不起作用。对象中的数据已更改 (menu.settings.menu),当 menu.disabled(true) 时 - 一切正常,但在其他情况下,我看到第一次生成的菜单项(即对象中的数据正在更改,下拉菜单中的项目不变)。
TinyMCE 不支持在编辑器初始化后动态添加项目到菜单。如果你必须这样做,你可以
- 先全部添加,然后 enable/disable 根据需要添加
- 用户
remove()
和init()
使用不同的菜单选项重新初始化编辑器