2015-08-28 107 views
1

我是ExtJS的新手。我在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是什么显示在下拉列表中的数据。

回答

1

这将是很容易的,一般情况下是

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

相关问题