0

I have a grid where the colmodel looks like:;

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:

{"name":"Name 1","group.id":"1","sql":"sql","oper":"edit","id":"1"}

But my server expects a multi-level json like:

{"name":"Name 1","group":{"id":1},"sql":"sql","oper":"edit","id":"1"}

My serializeEditData looks like:

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?

Erkan
  • 151
  • 2
  • 11

1 Answers1

0

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

sajawikio
  • 1,516
  • 7
  • 12
  • Here a very generic function [link](http://stackoverflow.com/a/7794127/1381730). This is exactly what I looked for – Erkan Sep 04 '12 at 20:04