有时网页后端传到前端的数据格式为json,我们需要把它展示在DataGrid里面,以下为操作代码:

                        var jsonString = '{"total":'+getJsonObjLength(json)+',"rows":'+JSON.stringify(json)+'}';            
                        //getJsonObjLength(json) 是为了得到json格式数据的长度
                     

                        var jsonObject = $.parseJSON(jsonString);
                        $("#datagrid").datagrid('loadData', jsonObject);

     

   获取json格式数据长度函数:

        function getJsonObjLength(jsonObj)
        {
            var Length = 0;
            for (var item in jsonObj) {
                Length++;
            }
            return Length;
        }

 

相关文章:

  • 2021-12-24
  • 2021-08-01
  • 2021-12-14
  • 2022-02-27
  • 2022-12-23
  • 2021-11-02
猜你喜欢
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案