How to select a specific record from the store in a ComboBox (ExtJS)

心不动则不痛 提交于 2019-12-11 13:43:12

问题


I have a ComboBox with a remote json store.

It lets the user type in 3+ characters, then queries, displays list and lets user select one option. When the user selects an option, it uses the Ext.data.Record associated to the selected option to populate other fields elsewhere in the form. This works correctly.

Now I want to be able to pre-populate the said fields, by using the functions that I've already written as part of the combo box. What I have come up with, is to add an "artificial record" to the ComboBox's store, and then force its selection - which would trigger all the right functions and populate the other fields etc..

What I have is this function inside of the ComboBox (I've created a custom one by extending ComboBox):

loadRecord : function( record ){
    var data = {
        "results":1,
        "rows":[
            record
        ]
    }

    this.store.loadData( data ); // I realize I could just use store.add() instead.

    alert( this.store.getCount() ); // returns 1, so the record is in

    // Here is where I'd need to make a call to select this record.
}

I've tried this.select() and this.selectByValue() but to no avail. Knowing the record is in the store, what is the right way to select it from code?

Thank you in advance.


回答1:


did you try combo.fireEvent('click', combo, record, index) ?




回答2:


How about this:

record = this.store.getAt(1);


来源:https://stackoverflow.com/questions/2023686/how-to-select-a-specific-record-from-the-store-in-a-combobox-extjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!