【问题标题】:jqgrid post multi-level jsonjqgrid发布多级json
【发布时间】:2012-09-03 23:17:01
【问题描述】:

我有一个网格,其中 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?

【问题讨论】:

    标签: javascript json jqgrid


    【解决方案1】:

    如果你开始,说

    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"}
    

    希望对你有帮助

    【讨论】:

    • 这里有一个非常通用的函数link。这正是我所寻找的
    猜你喜欢
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-17
    • 1970-01-01
    相关资源
    最近更新 更多