我有一个网格,其中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'},
{name:'sql',index:'sql', editable:true, width:100}
],
当我现在编辑数据并将其发布到服务器时,json看起来像:
{"name":"Name 1","group.id":"1","sql":"sql","oper":"edit","id":"1"}
但我的服务器需要一个多级json,如:
{"name":"Name 1","group":{"id":1},"sql":"sql","oper":"edit","id":"1"}
我的serializeEditData如下所示:
serializeEditData:function(data) {
if (data.id === '_empty')
data.id = null;
return JSON.stringify(data)
}
是否有一种优雅的方式将javascript对象格式化为多级json?
答案 0 :(得分:0)
如果你开始,说
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"}
希望这有帮助