combo 添加listeners,使用 initComponent、constructor 的區別

LocationCombo = Ext.extend(Ext.form.ComboBox,{
    initComponent: function(){
        var config = {
             name: 'loactionCombo'
            ,hiddenName: 'loactionCombo'
            ,fieldLabel: '所在區域'
            ,store: [['-1','請選擇...']]
            ,triggerAction: 'all'
            ,mode: 'local'
            ,autoScroll: true
            ,expandPanel : new LocationTree()
            ,listeners: {
                'expand': function(){
                    alert('expand...');
//                    if(!combo.expanded){
//                        combo.expandPanel.render(combo.el);
//                        combo.doLayout();
//                        combo.expanded =  true;
//                        //applyToMarkup
//                    }
                }
                ,'collapse': function(){
                    alert('collapse');
                    //document.getElementById('tree').innerHTML='';
                }
            }
        }
        this.addListener('expand',function(){alert('2expand..')});
        Ext.apply(this, config);
        LocationCombo.superclass.initComponent.call(this);
    }

});

使用initComponent時,在config對象中寫listeners無效,需使用方法添加。而使用constructor則支持 在config對象中寫listeners,但ext.2.0不支持constructor.

發佈了17 篇原創文章 · 獲贊 4 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章