Ext.Ajax.request怎么传递对象到后台Action

var cell=grid.getSelectionModel().each(function(rec){
// var jsonBean={dept:{id:rec.get('dept.id'),CDept:rec.get('dept.cDept'),CDeptname:rec.get('dept.cDeptname')}};
//var newJson=Ext.encode(Ext.decode(jsonBean));

                       Ext.Ajax.request({
                       url: 'addTJdept.action',
                       method: 'POST',
                        scope: this,
                        params:{
                           id:rec.get('dept.id')
                        },
                        success: function(response, opts){

。。。。。。。。。。。。。
我用的是Struts2+Spring+Hibernate+Extjs
是用Extjs的EditorGridPanel进行修改,不能弹出修改窗体,就直接在表格里修改,然后点击保存提交
上面我注释掉的代码是测试用的 可以获得我选择行的任何值
不过下面的params传参 只能传个字段,不能传一个对象么?
如果用form表单的话,Struts2会自动帮我填充到对象中,
Ext.ajax.request不行么?
我的action返回的是JSON对象的,这里主要就是传个dept这个对象该怎么传到后台Action中

不清楚的你的实体是什么,但是使用json对象可以的

。比如你action里有

private User user;

User里有name和age

那么你就可以构造你的json

var jsonBean={'user.name':'张三','user.age':18};

然后params:jsonBean就可以了!

只要是json的格式的 就行

params的参数可以把你要传的值写成一个json对象传递的。你定义一个json对象就好了。封装你的参数

引自官方api
[code="java"]Ext.Ajax.request({
url: 'foo.php',
success: someFn,
failure: otherFn,
headers: {
'my-header': 'foo'
},
params: { foo: 'bar' }//参数名foo 参数值bar
});

[/code]

其中的params可以
var jsonBean={dept:{id:rec.get('dept.id'),CDept:rec.get('dept.cDept'),CDeptname:rec.get('dept.cDeptname')}};

params: jsonBean 这样即可

既然是 struts2 他会默认帮你组转这个对象的!

你可以在 action里面定义一个 dept 类型的对象!

然后在传参数的时候

url: 'addTJdept.action?dept.deptid=123&dept.cDept'=456',

这样传到action 然后就可以调用 dept 这个属性了! 封装好了的! 试试看!

var json= [];
json.push({
id:rec.get('dept.id'),
CDept:rec.get('dept.cDept'),
CDeptname:rec.get('dept.cDeptname'}
})

params: { dept: Ext.encode(json) }

然后后台解析!
这样应该行的

[code="java"]
var json= [];
json.push({
id:rec.get('dept.id'),
CDept:rec.get('dept.cDept'),
CDeptname:rec.get('dept.cDeptname'}
})

params: { dept: Ext.encode(json) }
[/code]

后台
private String dept; 然后set get

JSONArray jsonArray = JSONArray.fromObject(dept);
JSONObject jsonObject = jsonArray.getJSONObject(0);
jsonObject这就是你向后台传的东西 然后做的操作

url: 'addTJdept.action?dept.deptid=123&dept.cDept'=456',

这样传到action 自动变成对象了! 赋值好了的!
然后就可以调用 dept 这个属性了!

你直接
data:{
objectName:{
"propertityName1":"value",
"propertityName2":"value",

}
}