您可以像这样创建本地组合:
// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
//...
]
});
var combo2 = Ext.create('Ext.form.ComboBox',{
// combo config;
});
// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local', //makes it a local combo. Don't need a url.
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody(),
listeners : {
select : function() {
var value = this.getValue();
combo2.setValue(value);
}
}
});
使用 的select
事件combo
将选定的值设置到第二个组合中。请注意,选择的值应该是在data
中定义的值store
,combo2
以便对其进行设置。在此处阅读 setValue 的文档以获取确切信息。
阅读评论后编辑:
您可以动态设置第二个组合的商店。将上面提到的选择事件更改为:
select : function()
{
var dataArray = [],data = this.getValue(); //Json string
dataArray.push(Ext.decode(data)); //In case there is only one object in the string instead of any array.
combo2.getStore().loadData(dataArray, false); //dataArray is automatically parsed into Model Objects. Second param to allow append to existing store data.
}
}