问题描述
|
我有以下代码:
var comboStore = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({
url : \'../cxf/rest/CustomerService/getGroups\'
}),reader : new Ext.data.JsonReader({
fields : [ \'id\',\'name\' ]
}),autoLoad : true
});
和
var groupsCombo = new Ext.form.ComboBox({
name : \'GroupsCombo\',fieldLabel : \'Groups\',mode : \'local\',store : comboStore,displayField : \'name\',triggerAction : \'all\',valueField : \'groupID\',selectOnFocus:true,width : 130
});
加载页面后,将在组合框中成功填充值。
但是,当我尝试从组合中选择一个值时,始终选择第一个值。我在这里不是以编程方式进行交谈,但是即使在浏览器上,也会选择第一个值。
谢谢
解决方法
抱歉:S我不知道我怎么没注意到这一点,但是Json数据存储区中的id应该是groupID而不是\'id \'。。我更改了它,现在可以正常工作了。
, 您是否尝试过仅使用JsonStore?尝试做这样的事情:
var comboStore = new Ext.data.JsonStore({
id: \'JsonStore\',idProperty: \'id\',autoLoad: true,root: <root of your JSON>,fields: [ \'id\',\'name\' ],proxy: new Ext.data.ScriptTagProxy({
api: {
read: \'../cxf/rest/CustomerService/getGroups\',}
})
});
然后使用ComboBox的商店。 JsonStore会自动创建一个JsonReader,我认为这就是您代码中的冲突所在。