【问题标题】:Slickgrid How to avoid cyclic complaint on JSON.stringify(dataView.getGroups())Slickgrid 如何避免对 JSON.stringify(dataView.getGroups()) 的周期性抱怨
【发布时间】:2013-10-11 01:38:25
【问题描述】:

我想使用 JSON.stringify 方法将 slickgrid 组数据转换为文本并发布到服务器。但是由于 JSON 对象是循环结构,它不起作用:

我使用的代码如下:

grps=JSON.stringify(dataView.getGroups()));

到目前为止,我有什么替代方法可以在当前数据视图中捕获 json 结果或对 getGroups() 对象进行字符串化?

我设法通过

获取dataView的项目
$.each(ar,function(index,value){
    db+=JSON.stringify(dataView.getItemById(value))+",";
    //db.push(dataView.getItemById(value));
    //console.log("row item: " + value+",data:"+JSON.stringify(dataView.getItemById(value)));
});

但这不是我想要的结果,因为它没有反映 json 字符串中的嵌套组结构。

感谢帮助

【问题讨论】:

    标签: jquery json slickgrid dataview


    【解决方案1】:

    我设法通过使用 foreach 将其转储到字符串中并手动组合它们来解决此要求: 一些不需要的列直接忽略它。

    function dumpgroup2json(obj,lv){
        var rs="[";
        $.each(obj,function(i,v){
            rs+="{";
            $.each(v,function(i1,v1){
    
    
            //  console.log("index: "+i+", 2ndlevel: " +i1+": "+v1);
                    if(i1=="rows"){
                        if(v1)
                            rs=rs+' "rows" : ' +dumprow2json(v1) + ',';
                        }
                        else if(i1=="groups"){
                            if(v1)
                                rs=rs+' "groups_'+lv+'" : ' +dumpgroup2json(v1,(lv+1)) + ',';
    
                        }
                        else if (i1=="level" ||i1=="count" ||i1=="value" || i1=="title"  )
                            rs+='"'+i1+'" : "'+v1+'",';             
    
            });
            rs=rs.substr(0,rs.length-1)+"";
    
            rs+="},";
        });
            rs= rs.substr(0,rs.length-1)+"]";
        //console.log(rs);
        return rs;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-17
      • 2020-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-03
      • 2011-01-25
      相关资源
      最近更新 更多