日期:2014-05-16 浏览次数:20462 次
/**
 * tbarCfg:{
 *         catUrl:"xx"
 * }
 */
MyToolbar = Ext.extend(Ext.Toolbar,{
    category:null,
    
    constructor:function(_cfg){
        
        Ext.apply(this,_cfg);
        MyToolbar.superclass.constructor.call(this,{
            height:40,
            items:this["category"],
            listeners:{
                "beforerender":function(_tbar){
                    Ext.Ajax.request({
                        url:this["tbCfg"].catUrl,
                        success:function(_response){
                            alert(_response.responseText);
                            this.category = _response.responseText;
                            
                        }
                    });
                    
                }
            }
        });
    }
}); 
MyToolbar.superclass.constructor.call(this,{
            height:40,
            items:[],//先配一个空的
            listeners:{
                "beforerender":function(_tbar){
                    var _this=this;//用一个局部变量保存this引用
                    Ext.Ajax.request({
                        url:this["tbCfg"].catUrl,
                        success:function(_response){
                            alert(_response.responseText);
                            var backData=eval(_response.responseText);//json字符串需解析为数组
                                for(var i=0;i<backData.length;i++)//动态添加项
                            {
                               _this.add(backData[i]);
                            }                            
                        }
                    });
                    
                }
            }
        });