0

我想使用 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();
        }
    });
};
4

1 回答 1

1

首先你需要get()工具栏菜单(见http://w2ui.com/web/docs/w2toolbar.get),然后你需要替换/扩展items工具栏菜单的数组:

w2ui.toolbar.get('processes').items = [
    { text: 'New Item 1', img: 'icon-page' },
    { text: 'New Item 2', img: 'icon-page' }
];

我强烈建议你也给你的物品一个id(见http://w2ui.com/web/docs/w2toolbar.items)。

于 2016-04-04T07:04:14.563 回答