组合框extjs的设定值

时间:2013-04-29 14:08:42

标签: combobox extjs4.1 setvalue

这是我的组合模型

Ext.define('ExtJS.myApp.ComboModel', {
    extend: 'Ext.data.Model',
    alias: 'widget.combomodel',
    fields: [
        { name: 'ID', type: 'int' },
        { name: 'title', type: 'string' }
     ]
});

这是comboStore

   this.comboStore = Ext.create('Ext.data.Store', {
        model: 'ExtJS.myApp.ComboModel',
        autoLoad: true,
        scope: this,
        proxy: {
            type: 'ajax',
            scope: this,
            url: 'myApp/GetRecords',
            reader: {
                type: 'json',
                root: 'data'
            }
        }
    });

    this.myComboBox = Ext.create('Ext.form.ComboBox', {
        store: this.comboStore,
        queryMode: 'local',
        displayField: 'title',
        valueField: 'ID'
    });

这是我为商店获得的json对象:

{"ID":"111","title":"Ext Page 1"}

现在当我尝试像这样设置组合框的值时。     this.myComboBox.setValue( '111');

组合框显示“111”而不是“Ext Page 1”

在设置valueField时,我需要做什么才能使组合框显示displayField。例如。我想将值设置为“Ext Page 1”供用户查看,但在保存值时,我实际上想要保存“111”

1 个答案:

答案 0 :(得分:5)

尝试:

this.myComboBox.setValue(111);

而不是:

this.myComboBox.setValue('111');