setValue()未在combox字段EXTJS中存储正确的值

时间:2018-09-05 21:14:55

标签: javascript extjs

我想动态设置一个值,

 $cls.superclass.constructor.call(this, Ext.apply({

              autoHeight: true,
              items: [
                this.combo = new Ext.form.ComboBox({
                  width: 75,
                  emptyText: $L('Select...'),
                  mode: 'local',
                  displayField : 'title',
                  valueField: 'key',
                  triggerAction: 'all',
                  store: new Ext.data.ArrayStore({
                       fields: ['key', 'title'],
                       data: [
                         ["titletest","Title"],
                         ["nametest","Name"]]
                   }),
                   listeners: {
 'select': function(){
  this.show();
},
scope: this
}
                })]



    },cfg));

我这样做:

show: function(fld) {
  this.combo.setValue(fld.value);
}

fld.value将值设置为“名称测试”或“标题测试”,而不是“标题”或“名称”

如何解决此问题?谢谢!

1 个答案:

答案 0 :(得分:0)

使用定义的字段中的键来定义数据,就像这样

fields: ['key', 'title'],
    data : [
            {"key":"titletest", "title":"Title"},
            {"key":"nametest", "title":"Name"}
    ]