首页 > 解决方案 > setValue() 没有在组合框字段-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 将值设置为“nametest”或“titletest”而不是“Title”或“Name”

如何解决这个问题?谢谢!

标签: javascriptextjs

解决方案


数据定义应该像这样使用定义的字段中的键'

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

推荐阅读