我在向组合框添加数据时遇到问题(这是我的代码:
{
xtype: 'combo',
name: 'accounttype',
triggerAction: 'all',
fieldLabel: '??? ?????',
labelWidth: 125,
displayField: 'name_y',
valueField: 'nzp_y',
width: 280,
emptyText: '??? ?????',
listeners: {
afterrender: function (item) {
Ext.Ajax.request({
url: 'account/combodata',
method: 'POST',
success: function (objServerResponse) {
var jsonResp = Ext.decode(objServerResponse.responseText);
if (jsonResp.success == true) {
var mystore = new Ext.data.JsonStore({
fields: ['nzp_y', 'name_y'],
data: [{ nzp_y: 0, name_y: ' '}]
});
var myArray = new Array();
for (var i = 0; i < jsonResp.combolist.length; i++)
{
if (jsonResp.combolist[i].nzp_res == 9999)
{
myArray['nzp_y'] = jsonResp.combolist[i].nzp_y;
myArray['name_y'] = jsonResp.combolist[i].name_y;
//???
}
}
}
},
failure: function (objServerResponse) {
Ext.Msg.alert('Error', objServerResponse.responseText);
}
});
}
},
store: mystore
}
如何将商店添加到组合中? 感谢。
答案 0 :(得分:1)
假设您使用的是ExtJS 4.x
我建议你使用Model-Proxy-Store
// Set up a model to use in your Store
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'nzp_y', type: 'int'},
{name: 'name_y', type: 'string'}
]
});
......其他一些代码
{
xtype: 'combo',
name: 'accounttype',
triggerAction: 'all',
fieldLabel: '??? ?????',
labelWidth: 125,
displayField: 'name_y',
valueField: 'nzp_y',
width: 280,
store: Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url: '/account/combodata',
reader: {
type: 'json',
root: 'data' // you may need to modify this
}
},
autoLoad: true
}),
emptyText: '??? ?????'
}
编辑以回答评论:
你定义应该看下面的配置(可以添加到root: 'data'
下面):
idProperty : 'id' // You seem not to have a id property based on the given values
totalProperty : 'total' // You don't have this one at all
请先检查这些并发布结果。对于给定的错误,我有这样的想法。从来没有见过这个。