0

I want to fill my w2ui toolbar menu item dynamically using javascript. I tried using: document.getElementById but it didn't work since theres no id for the dropdown menu.

the section processes is the one that I'm trying to fill dynamically

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();
        }
    });
};
carlkassar
  • 7
  • 1
  • 5

1 Answers1

1

First you need to get() the toolbar menu ( see http://w2ui.com/web/docs/w2toolbar.get ), then you need to replace / extend the items array of the toolbar menu:

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

I strongly recommend you give your items an id, too ( see http://w2ui.com/web/docs/w2toolbar.items ).

Mike Scotty
  • 10,530
  • 5
  • 38
  • 50