[英]jqgrid post multi-level json
I have a grid where the colmodel looks like:; 我有一个网格,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}
],
When I now edit the data and post it to the server the json looks like: 现在,当我编辑数据并将其发布到服务器时,json如下所示:
{"name":"Name 1","group.id":"1","sql":"sql","oper":"edit","id":"1"}
But my server expects a multi-level json like: 但是我的服务器需要一个多级json,例如:
{"name":"Name 1","group":{"id":1},"sql":"sql","oper":"edit","id":"1"}
My serializeEditData looks like: 我的serializeEditData看起来像:
serializeEditData:function(data) {
if (data.id === '_empty')
data.id = null;
return JSON.stringify(data)
}
Is there an elegant way to format javascript objects as multi-level json? 有没有一种优雅的方式将javascript对象格式化为多级json?
if you start with, say 如果您开始说
var jsobj = {"name":"Name 1","group":"","sql":"sql","oper":"edit","id":"1"};
I think doing simply 我认为做简单
jsobj["group"] = {"id" : 1};
console.log(jsobj);
should work and result in: 应该起作用并导致:
{"name":"Name 1","group":{"id":1},"sql":"sql","oper":"edit","id":"1"}
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.