是这样的,我在项目中用到jsonplugin的jar包,现在想实现的是一个下拉列表,后台的action用的是map类型(不知道对不对),前台得到的数据是这样:
{"message":null,"success"alse,"userDto":{"password":null,"passwordConfirm":null,"type":{"2":"普通用户","1":"管理员"},"username":"aaa"},"userType":"success"}但是感觉"type":{"2":"普通用户","1":"管理员"}这个格式不对,不知道怎么添加到下拉列表框中(也就是extjs的combobox),还是我思路有问题,请指教!!我真正想要获得的格式应该是这样:{type:[{id:1,name:"普通用户"},{id:2,name:"管理员"}]},但不知道如何实现? 或者各位说下用jsonplugin后台怎么生成combobox的数据格式呢???
{"message":null,"success"alse,"userDto":{"password":null,"passwordConfirm":null,"type":{"2":"普通用户","1":"管理员"},"username":"aaa"},"userType":"success"}但是感觉"type":{"2":"普通用户","1":"管理员"}这个格式不对,不知道怎么添加到下拉列表框中(也就是extjs的combobox),还是我思路有问题,请指教!!我真正想要获得的格式应该是这样:{type:[{id:1,name:"普通用户"},{id:2,name:"管理员"}]},但不知道如何实现? 或者各位说下用jsonplugin后台怎么生成combobox的数据格式呢???
解决方案 »
- JS如何设置按钮的边框颜色
- 用JS怎么获取某容器里的字体颜色和大小?
- IE6 和IE8 iframe刷新问题
- *********************请问关于iframe的问题,救命!!!*****************
- [产品探讨]/*作js菜单用那款工具最合适?*/
- ★★★ 关于javascript面向对象技术中 prototype的用途 ★★★
- 有什么办法隐藏select中的部分option吗?
- 高分求javascript效果的菜单一条。。。。差的不要。。。满意起价200分。
- 如何动态的获取层的id
- 关于table的一些问题
- XML在chrome 谷歌浏览器里面读不出来 IE和ff里面是好的
- 在ie8中能够自适高的js 在firefox就不行?
如你的combobox 只绑定 类型
你可以在后台拼接html
comboboxHtml:"<select><option value=1>普通用户</optin><option value=2>管理员</optin></select>"
Ext.onReady(function() { //创建json数据
var education = {"message":null,"success":false,
"userDto":{"loginType":[{"id":1,"typeName":"管理员"},
{"id":2,"typeName":"普通用户"}],
"password":null,
"passwordConfirm":null,
"username":null},
"userType":"success"};
//把json数据load到内存
var proxy = new Ext.data.MemoryProxy(education);
/* 注意:这里如果我换成这种方式,就不行了,而返回的数据格式和education 的格式一摸一样
var proxy = new Ext.data.HttpProxy({
url:"getUserType",
method:"POST"
});*/
//创建表头关联
var record = new Ext.data.Record.create([{
name:"id",type:"int",mapping:"id"
},{
name:"typeName",type:"string",mapping:"typeName"
}]);
//创建json解析器
var reader = new Ext.data.JsonReader({
root:"userDto.loginType",
fields:record
});
//创建数据商店
var store = new Ext.data.Store({
proxy:proxy,
autoLoad:true,
reader:reader
});
//学历
var cbxEducation = new Ext.form.ComboBox({
fieldLabel:"最高学历",
allowBlank:false,
renderTo:Ext.getBody(),
width:200,
name:"education",
emptyText:"请选择",
store:store,
mode:"local",//用远程访问的话我这里也该成remote了,真是奇怪
triggerAction:"all",
displayField:"typeName",
valueField:"id",
msgTarget:"side",
editable:false //设置文本框是否可编辑
});
var btn = new Ext.Button({
text: "列表框的值",
renderTo: Ext.getBody(),
handler: function(){
Ext.Msg.alert("值", "实际值:" + cbxEducation.getValue() + ";显示值:" +
cbxEducation.getRawValue());
}
});
});