当调用setValue时,Extjs ComboBox不会选择正确的值 [英] Extjs ComboBox doesn't pick the correct value when setValue is called
本文介绍了当调用setValue时,Extjs ComboBox不会选择正确的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
// Part of a larger form.
{
xtype: 'combo',
id: 'enroller',
valueNotFoundText: 'not found',
triggerAction: 'all',
mode: 'local',
fieldLabel: 'Enroller',
store: new Ext.data.JsonStore({
url: url,
root: 'data',
autoLoad: true,
fields: ['enrollerID', 'name', 'key']
}),
displayField: 'name',
valueField: 'key',
hiddenName: 'enrollerID',
forceSelection: true
}
// Other area of code.
Ext.getCmp('enroller').setValue(289);
即使我可以确认商店有一个如下记录:
Even though I can confirm the store has a record that looks like:
{"name":"Test Enroller","enrollerID":"289","key":"289"}
组合框显示valueNotFoundText。如何获取组合来加载正确的记录?
The combo box displays the valueNotFoundText. How can I get the combo to load the correct record?
推荐答案
最后使用此代码。我迫使组合框仅在商店加载其值后加载值。在商店加载其价值之前,它被设置好。
Finally got it working with this code. I force the combo box to load the value only after the store has loaded its values. Before it was getting set before the store loaded its values.
{
xtype: 'combo',
fieldLabel: 'Enroller',
ref: 'enroller',
store: {
xtype: 'jsonstore',
url: context + '/store.do',
baseParams: { 'class': 'scheduler.Enroller' },
autoLoad: true,
listeners: {
load: function() {
me.enroller.setValue(me.enroller.getValue());
}
}
},
displayField: 'name',
valueField: 'enrollerID',
hiddenName: 'enrollerID',
triggerAction: 'all'
}
这篇关于当调用setValue时,Extjs ComboBox不会选择正确的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文