Json jqGrid中的嵌套对象

Json jqGrid中的嵌套对象,json,jqgrid,Json,Jqgrid,我有一个处理JSON数据的jqGrid,它有嵌套对象。我正在使用jsonmap设置colmodel,它工作得很好;但当我试图编辑一行时,传递给服务器的JSON只包含jsonmap属性,而不包含整个对象,因此无法将JSON映射到Java对象 JSON如下所示: {'id': 1, 'name': 'blah', 'importantData': {'importantDataId': 145, 'importantDataName': 'bleh'} } {name:'

我有一个处理JSON数据的jqGrid,它有嵌套对象。我正在使用jsonmap设置colmodel,它工作得很好;但当我试图编辑一行时,传递给服务器的JSON只包含jsonmap属性,而不包含整个对象,因此无法将JSON映射到Java对象

JSON如下所示:

{'id': 1,
 'name': 'blah',
 'importantData':
     {'importantDataId': 145,
      'importantDataName': 'bleh'}
}
{name:'id', label:'ID', editable: false},
{name:'name', label:'Name', editable: true},
{name:'importantData_name', label:'Important Data', jsonmap: 'importantData.importantDataName', editable: false}
{'id': 1,
 'name': 'newName',
 'importantData_name', 'bleh'}
serializeEditData: function (postData) {
    postData.importantData = myImportantData;
    var data = JSON.stringify(postData, function(key, value) {
        if(key == importantData_name) {
            return undefined;
        }
    }
}
jqGrid模型如下所示:

{'id': 1,
 'name': 'blah',
 'importantData':
     {'importantDataId': 145,
      'importantDataName': 'bleh'}
}
{name:'id', label:'ID', editable: false},
{name:'name', label:'Name', editable: true},
{name:'importantData_name', label:'Important Data', jsonmap: 'importantData.importantDataName', editable: false}
{'id': 1,
 'name': 'newName',
 'importantData_name', 'bleh'}
serializeEditData: function (postData) {
    postData.importantData = myImportantData;
    var data = JSON.stringify(postData, function(key, value) {
        if(key == importantData_name) {
            return undefined;
        }
    }
}
请注意,importantData不可编辑,但必须显示在网格和表单中

正如我所写的,这很好,我认为bleh是重要数据列中的值。 当我点击导航栏网格的编辑按钮时,我看到了用当前值编辑数据的表单。ID不显示,因为它不可编辑,而importantData显示为bleh。我更改表单中的名称并保存,发送到服务器的JSON如下所示:

{'id': 1,
 'name': 'blah',
 'importantData':
     {'importantDataId': 145,
      'importantDataName': 'bleh'}
}
{name:'id', label:'ID', editable: false},
{name:'name', label:'Name', editable: true},
{name:'importantData_name', label:'Important Data', jsonmap: 'importantData.importantDataName', editable: false}
{'id': 1,
 'name': 'newName',
 'importantData_name', 'bleh'}
serializeEditData: function (postData) {
    postData.importantData = myImportantData;
    var data = JSON.stringify(postData, function(key, value) {
        if(key == importantData_name) {
            return undefined;
        }
    }
}
服务器无法解析此JSON,因为它希望接收整个对象importantData或至少其ID

我已经配置了serializeEditData函数从网格中检索整个对象,并将整个对象或de ID添加到JSON中,但我无法获取整个importantData对象。有什么想法吗


提前谢谢

我所做的是使用jqGrid的serializedEditData方法,并将其设置为覆盖importantData\u name。 是这样的:

{'id': 1,
 'name': 'blah',
 'importantData':
     {'importantDataId': 145,
      'importantDataName': 'bleh'}
}
{name:'id', label:'ID', editable: false},
{name:'name', label:'Name', editable: true},
{name:'importantData_name', label:'Important Data', jsonmap: 'importantData.importantDataName', editable: false}
{'id': 1,
 'name': 'newName',
 'importantData_name', 'bleh'}
serializeEditData: function (postData) {
    postData.importantData = myImportantData;
    var data = JSON.stringify(postData, function(key, value) {
        if(key == importantData_name) {
            return undefined;
        }
    }
}
通过这段代码,我避免了将importantData_name包含在dejson中,并且在整个对象中包含了一个新属性importantData。 当我加载jqGrid以在这一点上使用它时,我必须保存整个对象

希望这对其他人有帮助