我想我有一个非常流行的问题,但现在没有找到答案。:) 我有 2 个类似的组合框 - 起初我通过 id 设置我的值 -comboT.setValue("22763");
它正确设置了与此 id 链接的文本值。在第二个组合框我首先重新加载存储(jsonstore)然后设置值 -comboC.setValue("3");
但是这个组合只设置 ID 而不是文本值(如果我打开列表我可以看到什么组合正确标记了文本值。然后(如果列表只是关闭而不选择)文本值在组合中正确显示。如何解决这个问题?谢谢。
问问题
29544 次
4 回答
12
像这样的东西,语法可能会稍微偏离,因为我是从记忆中做的:
var val = 3;
var store = comboC.getStore();
store.on("load", function() {
comboC.setValue(val);
}):
store.load();
于 2010-09-23T19:27:03.310 回答
6
加载存储是异步的,您可能希望将设置新值移动到 的callback:
事件处理程序中store.load({...})
,因为否则,您会在实际加载存储之前设置值。
编辑:为了完整起见,举个例子,所以你有一个替代版本(在某些情况下,可能不希望将回调绑定到商店本身,就像 ormuriauga 所做的那样):
var val = 3;
var store = comboC.getStore();
store.load({
callback: function() {
comboC.setValue(val);
}
});
于 2010-09-23T19:25:26.730 回答
2
关于如何通过在底层数据存储中搜索字符串来设置组合框值的另一个示例。我可以通过使用这些答案中的示例作为基线来编写代码:
//The store's data definition must have at least a data.id field defined
set_combobox_value_from_store = function (combobox, valueField, value) {
//Get a reference to the combobox's underlying store
var store = combobox.getStore();
store.load({
callback: function () {
//Find item index in store
var index = store.find(valueField, value, false);
if (index < 0) return;
//Get model data id
var dataId = store.getAt(index).data.Id;
//Set combobox value and fire OnSelect event
combobox.setValueAndFireSelect(dataId);
}
});
于 2011-05-12T21:43:13.840 回答
1
在 extjs 4.1 中,当模型中的 valueField 类型为“字符串”时,combo.setValue() 似乎有效。这是我的代码
Ext.define('Model.CboObras', {
extend: 'Ext.data.Model',
idProperty: 'co_obra',
fields: [{
name: 'co_obra',
type: 'int'
}, {
name: 'nb_obra',
type: 'string'
}]
});
这不起作用。
当我将代码更改为:
Ext.define('Model.CboObras', {
extend: 'Ext.data.Model',
idProperty: 'co_obra',
fields: [{
name: 'co_obra',
type: 'string'
}, {
name: 'nb_obra',
type: 'string'
}]
});
之后我使用这个:
var store = comboC.getStore();
store.load({
callback: function() {
comboC.setValue(val);
}
});
它现在就像一个魅力!
于 2012-12-24T16:36:57.917 回答