开发者

Ext JS scope issue

This is oldish code but anyway...

I a开发者_如何转开发m trying to filter a store, and listen to the event in a comboBox, so I can refresh it. My doQuery event didnt work, ( well actually it did work, but returned random result sets, leaving an overall wtf feeling )

    config.store.filterBy(function Filter(record){
    //this works
        if (record.data.field != ""){
            return true;
        }
        else {return false;}
    });

However this does not automagically update the combobox. So I tried various versions of

    cbx = new Ext.getCmp(this);     
    debugger; //scope right here    
    this.getStore().on("datachanged",function refresh(){
         cbx.reset();// store's scope
    });

But the scope of cbx always seems to be the store, instead of the combobox.

Anyone have any a clue how to do add said a listener for the data change event in a store to a comboBox?


The default scope of an event callback is the object that triggered the event. In this case that would be the store. The third parameter of the method on() allows you to override the scope. Set the third parameter to this and your good to go.

From the documentation (3.x and 4.x):

on( String eventName, Function handler, [Object scope], [Object options] )

So something like this should do the trick:

this.getStore().on("datachanged", function refresh() {
     cbx = Ext.getCmp(this);
     cbx.reset();
}, this); // <-- Provide scope for the callback function


You can always set the scope of a function in ExtJS (I assume you're using ExtJS 3.x) with Function.createDelegate.

this.getStore().on("datachanged",function() {
     cbx.reset();
}).createDelegate(this);

Although from the code sample you've provided, I'm not sure what the problem is since cbx.reset() shouldn't have any scope problems.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜