开发者

Toolbar items added/inserted into Ext.ToolBar aren't showing on the page

I have a custom component that extends a panel. The panel has a top tool bar with a basic config. I want to be able to add items to the panel dynamically after it has been created.

Those items should always come at the end of the main set of menu items and before the filler that pushes the logout button to the far right, so I wrote the insertMenuItem function to grab the position of the "shunt" (the tbfill) item and insert the new toolbar item at this location. If it doesn't find the "shunt", because its been overridden, it just adds to the end of the toolbar.

This seems to work just great. If I look at the "live" contentPanel I can see the inserted menu item. The problem come with getting it to display. Now I suspect that this is a scoping issue, I'm just not sure what, where, when, how.... :|

I've tried this.doLayout(), topToolbar.doLayout() in the function I've got a doLayout() on the contentPanel object after calling my function, but none of them seem to help.

HELP! ;-D

Below is my extended Panel class. Thanks in advance for your help

Stephen


SOM.ux.contentPanel = Ext.extend(Ext.Panel, {
     autoScroll:true
    ,initComponent:function() {
        var config = {
             plugins:['dispatcher']
            ,contentEl : Ext.get('som-body')
            ,tbar:{
                     itemId:'contenttoolbar'
                    ,items:[
                {
                    xtype : 'button',
                    text: 'Dashboard',
                    handler: function(){
                        document.location.href = '/'
                    }
                },{itemId:'shunt',xtype: 'tbfill'},{
                    xtype : 'button',
                    text: 'Logout',
                    handler: function(){
                        document.location.href = '/admin.login.doLogout'
                    }
                },{
                        xtype : 'tbbutton',
                        text: 'Message',
                        scope: this,
                        handler: function(){
                            this.publish('SOM.ux.Dashboard',{action:'doHelloWorld',params:{name:'Stephen'}});
                        }
                    }
                ]
            }

        }; // end of config
        Ext.apply(this, Ext.apply(this.initialConfig, config));
        SOM.ux.contentPanel.superclass.initComponent.apply(this, arguments);
    }
    ,afterRender: function(){
        this.subscribe('SOM.ux.Toolbar');
        SOM.ux.contentPanel.superclass.afterRender.call(this);
    }
    ,onDispatchMessage: function(subject,message) {
        if (message.action) {
            this[message.action].call(this,message.params);
        }       
        console.log('contentpanel doDispatch',subject,message);
    }
    ,insertMenuItem: function(itemObj){
        var topToolbar = this.getTopToolbar();
        var aItems = topToolbar.items;
        var insertPos = aItems.indexOfKey('shunt');
        if (inser开发者_Python百科tPos) {
            console.log('using insert');
            topToolbar.insert(insertPos,itemObj);
        } else {
            console.log('using add');
            topToolbar.add(itemObj);
        }
        this.getTopToolbar().doLayout();
    }


The following works:

var tb = new Ext.Toolbar({
    items : [{text : 'wtf'}]
});

new Ext.Window({
    width : 300,
    height : 100,
    tbar : tb
}).show();

(function() {
    tb.add({text:'new btn'});
    tb.doLayout()
}).defer(1500);

To add to jonathan's comment, only call doLayout after it's rendered.


Make sure you are calling insertMenuItem after the toolbar has rendered. Is itemObj (the param) an Ext.Toolbar.Item config?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜