我无法添加/覆盖组合侦听器

时间:2011-03-09 04:05:03

标签: extjs

我有2个js文件,一个定义了组合,第二个文件是一个调用组合声明的窗口。
在窗口文件中,我尝试添加或覆盖一些监听器,但监听器不起作用

这是组合:

App.form = function() {
    return {
        ComboCouch: function(config) {  
            var store = new Ext.data.JsonStore({
                autoDestroy: true,
                autoLoad:(config.autoLoad==true)?true:false,
                storeId :config.storeId,
                url: config.couchView,
                root: 'rows',
                fields: ['key', 'value']
            });
            var combo = new Ext.form.ComboBox({
                store: store,
                valueField: "key",
                displayField: "value",
                typeAhead: true,
                mode: 'local',
                forceSelection: true,
                triggerAction: 'all',
                selectOnFocus:true/*, this when i try to override
                listeners: {
                    'expand': function(c) {
                        c.store.reload();
                    }
                }*/
            });
            Ext.apply(combo,config);
            return combo;
        }
    };
}();

Ext.reg("appcombocouch",App.form.ComboCouch);

这是我的窗口:

App.Download = function() {
    return {
        dialog : null,
        init : function() {
            this.baseUrl = '/';
            this.whoami = null;

            if (!App.urlRewrite) this.baseUrl = '/' + App.database + this.baseUrl;

            if (App.Privilage.length==2 && (App.Privilage =="00" || App.Privilage <=0)) this.whoami = "Admin";
            else if (App.Privilage.length==2 && (App.Privilage !="00" || App.Privilage >0)) this.whoami = "Prop";
            else this.whoami = "Kab";
        },

        createItems : function(){
            var items = new Array(); 

            if(this.whoami == "Admin"){
                items.push({
                    fieldLabel: 'Pilih Provinsi',
                    title : 'Provinsi',
                    xtype: 'appcombocouch',
                    couchView : 'r_propinsi',
                    width:250,
                    name : 'kd_prop',
                    autoLoad : true,
                    scope : this,
                    //this, i want to add/pverride listener
                    listeners: {
                        'expand': function(c) {
                            Ext.Msg.alert("test","do you see me");// this alert never show, when the combo expanded
                            c.store.reload();
                        }
                    }
                });
            }

            var form = new Ext.form.FormPanel({
                labelWidth:110,
                //url:'php/download.php',
                frame:true,
                autoHeight:true,
                title:'Download DBF', 
                defaultType:'textfield',
                monitorValid:true,
                items : [items]
            })
            return form;
        },      

        show : function() {
            if (!this.dialog) {
                this.dialog = new Ext.Window({
                    items: [this.createItems()],
                });
            }
            this.dialog.show();
        }
    };
}();

Ext.onReady(App.Download.init, App.Download, true);

1 个答案:

答案 0 :(得分:0)

您正在尝试在已创建并初始化Ext.form.ComboBox后应用配置。试试这个:

ComboCouch: function(config) {  
    var store = new Ext.data.JsonStore({
        autoDestroy: true,
        autoLoad:(config.autoLoad==true)?true:false,
        storeId :config.storeId,
        url: config.couchView,
        root: 'rows',
        fields: ['key', 'value']
    });
    var comboConfig = {
        store: store,
        valueField: "key",
        displayField: "value",
        typeAhead: true,
        mode: 'local',
        forceSelection: true,
        triggerAction: 'all',
        selectOnFocus:true,
        listeners: {
            'expand': function(c) {
                c.store.reload();
            }
        }
    };
    Ext.apply(comboConfig, config);
    var combo = new Ext.form.ComboBox(comboConfig);
    return combo;
}