我想使用 javascript 动态填充我的 w2ui 工具栏菜单项。我尝试使用:document.getElementById
但它不起作用,因为下拉菜单没有 id。
部分流程是我试图动态填充的部分
ToolBarView.prototype.buildView = function(processController) {
$('#MDItoolbar').w2toolbar({
name: 'toolbar',
items: [
{ type: 'button', id: 'saveProcess' , name: 'saveProcess', caption: 'save Process', icon: 'fa-check', checked: true },
{ type: 'break', id: 'break0' },
{ type: 'button', id: 'NewProcess' , name: 'NewProcess', caption: 'New Process', icon: 'fa-check', checked: true },
{ type: 'break', id: 'break1' , name: 'break1' },
{ type: 'menu', id: 'processes', caption: 'Drop Down', img: 'icon-folder',
name:'processes',
items: [
{ text: 'Item 1', img: 'icon-page' },
{ text: 'Item 2', img: 'icon-page' },
{ text: 'Item 3', img: 'icon-page' }
]
},
{ type: 'break', id: 'break3' ,name:'break3'},
{ type: 'spacer',name:'spacer' }
]
});
w2ui.toolbar.on('*', function (event) {
console.log('EVENT: '+ event.type + ' TARGET: '+ event.target, event);
if (event.target =='saveProcess')
{
var saveProcess = new SaveProcessView("save the process",processController);
}
if (event.target =='NewProcess')
{
processController.NewProcess();
}
});
};