extjs 控件中拿取通过ajax传过来的json数据问题

2025-01-12 04:18:22
推荐回答(3个)
回答1:

Ext.namespace('user');
//接受后台传回的json格式的数据
user.roleReader = new Ext.data.JsonReader(
{root: 'treemap',id:'id'},
new Ext.data.Record.create([
{name:'id'},
{name:'text'},
{name:'depict'},
{name:'leaf'}
])
);

// 创建后台请求
user.roleStore = new Ext.data.Store({
reader: user.roleReader,
proxy: new Ext.data.HttpProxy({
method:'POST',
url:"role_getRoleAll.action"})
});

//加载后台请求
user.roleStore.load();

将下面的放到一个panel 中.
{
xtype:'combo',
id:'roleid',
fieldLabel:'用户角色',
//显示所有数据
triggerAction:"all",
//取数据的store
store:user.roleStore,
//从本地获取
mode:"local",
//现实值 (user.roleReader 中的name 对应)
displayField:'text',
//隐藏值
valueField:'id',
allowBlank:false
}

回答2:

checkBoxPanel 中增加事件监听,在处理函数是用ajax调用后台action,
Ext.Ajax.request({
//code...,
success:function(response){
var data = Ext.decode(response.responseText);//这样能取到值,如果是list的话传过来转化后应该是数组了。里面再是对象。最后再给checkBoxPanel赋值
}
});

回答3:

var data = Ext.decode(response.responseText);
这样就是一个对象了,可以拿里面的值了