EXTJS COMBOX - 商店做负载,但并没有显示
问题描述:
鉴于以下的javascript:EXTJS COMBOX - 商店做负载,但并没有显示
var fo = Ext.create('Ext.form.Panel', {
layout:'box',
...
items: [{
xtype: 'combobox',
valueField: 'id',
displayField: 'organizationtype',
store: {
storeId: 'zaza',
fields: [{name: 'id'}, {name: 'organizationtype'}],
root: 'data',
autoLoad: true,
proxy: {
type: 'ajax',
url: '/apps/crm_organizations/orgtype/',
reader: {
type: 'json'
}
}
},
fieldLabel: 'Type relation',
name: 'organizationtype',
queryMode: 'local',
},
...
此面板包含 - 也是这个组合框 - 其他领域。我可以用wireshark看到URL'/ apps/crm_organizations/orgtype /'实际上被查询。但是,组合框不显示任何值。这是否与我懒加载组合框的事实有关?
这是在JSON请求的响应:
{data: [ {id:"1" ,organizationtype:"Customer"}
,{id:"2" ,organizationtype:"Relation"}
,{id:"3" ,organizationtype:"Supplier"}
,{id:"4" ,organizationtype:"Unknown"} ]}
答
你必须根设置为您所使用的JSON读者,默认为“”,你的应该是:
reader: {
type: 'json',
root: 'data'
}
您也可以考虑用模型对象(来自docs)字段来替换字段配置:通常应避免使用此配置选项,它存在用于向后兼容的目的
答
更改组合框模式,从本地到远程mode: 'remote'
和使用JSON店:
store: {
xtype: 'jsonstore',
url: '/apps/crm_organizations/orgtype/',
autoLoad: true,
idProperty: 'id',
root: 'data',
fields: ['id','organizationtype'],
},
mode: 'remote'
答
在你的店,你错过了root属性
store: {
storeId: 'zaza',
fields: [{name: 'id'}, {name: 'organizationtype'}],
root: 'data',
autoLoad: true,
proxy: {
type: 'ajax',
url: '/apps/crm_organizations/orgtype/',
reader: {
type: 'json',
root:'data'
}
}
}
,如果你的组合是跨域查询信息,然后使用JSONP配置并使用远程查询获得更好的性能
Thanx,解决方案和学习点,切换到模型! – Paul 2012-07-24 12:09:34