您的位置:首页 > Web前端 > JavaScript

extjs JsonStore加载数据,Combobox只显示最后一项值问题

2012-05-05 10:21 633 查看
extjs3.3.1版本

JsonStore代码

var sexStore_para = new Ext.data.JsonStore({//对应类别store
url:'/himp/related_user_info!getTheDataProvidedToComboboxAjax.action',//'/financeStaff.do?method=dictData',
// root:'model',

fields:[{
name:'returnValue',
mapping:'itemid'
},{
name:'displayText',
mapping:'itemname'
}]
});


请求返回Json数据

[{"id":0,"itemid":"","itemname":"<全部>","pycode":null,"wbcode":null,"gbcode":null,"parentcode":null,"issys":null,"numvalue":null},{"id":2,"itemid":"1","itemname":"男","pycode":null,"wbcode":null,"gbcode":null,"parentcode":null,"issys":"2","numvalue":null},{"id":2,"itemid":"2","itemname":"女","pycode":null,"wbcode":null,"gbcode":null,"parentcode":null,"issys":"2","numvalue":null},{"id":2,"itemid":"9","itemname":"未知","pycode":null,"wbcode":null,"gbcode":null,"parentcode":null,"issys":"2","numvalue":null}]


id代表的是数据库中的一个字段,代表的是类型ID,而非位置的id值

问题;



如何解决这个问题:

需要将以上代码改正为一下代码:

var sexStore_para = new Ext.data.JsonStore({//对应类别store
url:'/himp/related_user_info!getTheDataProvidedToComboboxAjax.action',//'/financeStaff.do?method=dictData',
// root:'model',
idProperty: 'itemid',
fields:[{
name:'returnValue',
mapping:'itemid'
},{
name:'displayText',
mapping:'itemname'
}]
});


在这个时候需要你手动指定
idProperty
如果你不指定默认为id,id值一样当然会在循环的过程中一直被覆盖值,直到最后看见的是该id的最后一项的值,改正后的效果.

问题解决后效果图:



combobox代码:

//性别类型
var sexCode_para = new Ext.form.ComboBox({//对应类别的下拉框
id: 'sexCode_para',
name:'sexCode_para',
store: sexStore_para,
width:60,
mode: 'local',
triggerAction: 'all',
valueField: 'returnValue',
displayField: 'displayText',
editable:false
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: