我是 ExtJS 新手。我在 ExtJS 中有一个组合框,我想加载商店的第一条记录作为组合框的默认值。这是我的代码
var cutoff = store_dynamic('nr/getCutOffDate', true);
var combo_value = //here i want to store the default value taken in the store
xtype: 'combobox',
margin: '0 10 0 0',
labelWidth: 80,
width: 240,
store: cutoff,
displayField: 'date',
valueField: 'dt_val',
fieldLabel: 'Cut-Off Date',
editable: false,
id: 'cutoffdate',
value: combo_value
这是商店中的数据
{"success":true,"metaData":{"fields":["date","dt_val"]},"data [{"date":"June 30, 2015","dt_val":"6\
/30\/2015"},{"date":"June 15, 2015","dt_val":"6\/15\/2015"}]}
dt_val
是组合框中显示的内容。
最佳答案
这真的很容易,一般情况是
var store = combo.getStore(),
value = store.getAt(0).get(combo.valueField);
combo.setValue(value);
或者,在您的特殊情况下:
combo_value = cutoff.getAt(0).get('dt_val');
但我猜想您的代码可能会出现问题,即在初始化组合框时商店尚未填充数据。您最好在组合的 afterrender
和 store 的 load
事件中执行此操作,并检查 combo.rendered
和 store 是否在设置组合的值之前,.getCount()>0
都是 true
。
关于javascript - 获取ExtJS中数据存储的某个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32262845/