Javascript jqgrid post多级json
我有一个网格,其中colmodel看起来像:Javascript jqgrid post多级json,javascript,json,jqgrid,Javascript,Json,Jqgrid,我有一个网格,其中colmodel看起来像: colModel:[ {name:'id',index:'id', width:30, sorttype:'int'}, {name:'name',index:'name', editable:true, width:200}, {name:'group.id',index:'group.id', editable:true, width:200, formatter:'select', edittype: 'select
colModel:[
{name:'id',index:'id', width:30, sorttype:'int'},
{name:'name',index:'name', editable:true, width:200},
{name:'group.id',index:'group.id', editable:true, width:200, formatter:'select', edittype: 'select'},
{name:'sql',index:'sql', editable:true, width:100}
],
当我现在编辑数据并将其发布到服务器时,json看起来像:
{"name":"Name 1","group.id":"1","sql":"sql","oper":"edit","id":"1"}
serializeEditData:function(data) {
if (data.id === '_empty')
data.id = null;
return JSON.stringify(data)
}
但我的服务器需要一个多级json,如:
{"name":"Name 1","group":{"id":1},"sql":"sql","oper":"edit","id":"1"}
我的数据如下所示:
{"name":"Name 1","group.id":"1","sql":"sql","oper":"edit","id":"1"}
serializeEditData:function(data) {
if (data.id === '_empty')
data.id = null;
return JSON.stringify(data)
}
是否有一种优雅的方式将javascript对象格式化为多级json?如果您从
var jsobj = {"name":"Name 1","group":"","sql":"sql","oper":"edit","id":"1"};
我认为这样做很简单
jsobj["group"] = {"id" : 1};
console.log(jsobj);
应工作并导致:
{"name":"Name 1","group":{"id":1},"sql":"sql","oper":"edit","id":"1"}
希望这有助于这是一个非常通用的函数。这正是我想要的