我是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和商店的load事件中执行此操作,并在设置组合的值之前检查combo.renderedstore.getCount()>0是否均为true

关于javascript - 在ExtJS中获得一定的数据存储值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32262845/

10-12 00:40
查看更多