简体   繁体   中英

Selectfield listener fires on view initialize

This is a bit hard to explain so I'm doing my best, please ask for more clarity if my problem is vague.

I'm filling a selectfield with options from a store. This form shows itself on a detailview that the user gets when he clicks on a row in my general listview. This all works flawless.

I use record.data in my push() to pass relevant data to the detailview and use the initialise listener to catch this data and populate some items on the detailview (title, form etc).

My selectfield has a change listener to do an ajax request once the field changes. What happens is that my selectfield first loads the options from a store, and then the initialize listener gets called.

Resulting in a ajax request everytime the view loads. Because my initialize listener changes the selectfield to show another option as active, the selectfield thinks something has changed and triggers the change listener.

What is the best way to set a selectfield option to active without triggering the change listener?

Selectfield with change listener:

xtype: 'selectfield',
itemId:'groundtype',
displayField: 'ground_name',    
valueField: 'ground_id',
store: 'groundTypeStore',
listeners: {
    change: function (data) {
        // execute ajax request on change
    }
}

Form panel (detailview) initialize listener

listeners: 
{
    initialize: function(){
        var value = this.config.record;

        if(value != null){
            this.down('#groundtype').setValue(value.groundtype);

        }
    }
}

Thanks in advance!

You can suspend the field's events while setting the value by using the suspendEvents function:

var field = this.down('#groundtype');
field.suspendEvents();
field.setValue(value.groundtype);
field.resumeEvents(true);

Note, that you need to pass true to resumeEvents in order to discard queued events.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM