将嵌套数据保存在ExtJS 4中

时间:2014-08-05 13:20:51

标签: extjs

我正在尝试保存在表单中捕获的嵌套数据。 (我也读过这个question

以下是模型的外观

Ext.define('App.model.Team',{
extend:'Ext.data.Model',
idProperty:'id',
fields:[
    {name:'id', type:'int'},
    {name:'name', type:'string'}, 
    {name:'description', type:'string'},
    {name:'orgUnitName', type:'string', mapping:'orgUnit.name'},  <----
],
proxy: {
    type:'ajax',
    url:'/odb/myteams/',
    reader: {
        type:'json',
        root:'data'
    }
}
});

控制器 ...

  saveNewTeam: function( button, e, eOpts ) {

   win = button.up( 'window' ),
   form = win.down( 'form' ),
   isForm = form.getForm();  

    record = isForm.getRecord(),
    values = isForm.getValues(),
    record.set( values );

    var jsonData = Ext.JSON.encode(isForm.getValues());


    Ext.Ajax.request({
        url : '/odb/myteams',
        method : 'POST',
        headers : {
        'Content-Type' : 'application/json'
        },
        params : jsonData,
        success: function (form, action) {

            Ext.Msg.alert('Status', 'Saved successfully.');
            win.close();
        },
        failure: function (form, action) {
            if (action.failureType === Ext.form.action.Action.SERVER_INVALID) {
                Ext.Msg.alert('SERVER_INVALID', action.result.message);
            }
        } 
        });
   }, 

我得到了错误的请求异常。

POST http://odb/myteams?_dc=1407243897827 400 (Bad Request) 

看起来发送的数据不是正确的json格式?

这是服务器所期望的:

{
     name: "Operation addedd",
     description: "Operation DataBase",
     orgUnit:{
        name:'DATA DATAPROCESSING GMBH'
     }
}

这是请求的发送方式

{ 
     name: "Operation addedd",
     description: "Operation DataBase",
     orgUnitName:'DATA DATAPROCESSING GMBH'

}

0 个答案:

没有答案