[原创]EasyUI的TreeGrid查询功能实现

最近需要实现对treeGrid的查询功能,具体查询界面如下:

可以查询根节点和具体子节点的信息,开始使用EasyUI的TreeGrid的loadData 加载url的方式不能实现查询功能,于是利用异步AJAX查询了一下数据返回后,赋值给变量,然后利用

TreeGrid的loadData加载这个json格式的返回结果实现了对TreeGrid的查询功能,代码如下:

    function searchROM() {

        var product = $('#Product').combobox('getValue');
        var keytype = $('#keytype').combobox('getValue');
        var keywords = $('#keywords').val();
        var url = encodeURI('/GoodsROM/ROMList?product=' + product + '&keytype=' + keytype + '&keywords=' + keywords+'&'+Math.random());
        $.post(url, {}, function(data) {
            var d = data;//返回json格式结果
            $('#grid').treegrid('loadData',d);//加载数据更新treegrid
        }, 'json');

    }

有网友照做,发现显示不出来,他的json数据格式为:

{"total":9,"rows":[{"Identifier":"1","Area_Name":"数据融合系统","_parentId":"-1"},{"Identifier":"2","Area_Name":"统计数据","_parentId":"1"},{"Identifier":"3","Area_Name":"全业务套餐发展量","_parentId":"2"},{"Identifier":"4","Area_Name":"状态统计查询","_parentId":"2"},{"Identifier":"5","Area_Name":"装拆机统计查询","_parentId":"2"},{"Identifier":"6","Area_Name":"产品(分客户群)装拆机统计","_parentId":"2"},{"Identifier":"7","Area_Name":"清单","_parentId":"1"},{"Identifier":"8","Area_Name":"子项一","_parentId":"7"},{"Identifier":"9","Area_Name":"子项二","_parentId":"7"}]}

问题出在treegrid支持的Json格式,根节点没有_parentId,应该如下格式:

{"total":9,"rows":[{"Identifier":"1","Area_Name":"数据融合系统"},{"Identifier":"2","Area_Name":"统计数据","_parentId":"1"},{"Identifier":"3","Area_Name":"全业务套餐发展量","_parentId":"2"},{"Identifier":"4","Area_Name":"状态统计查询","_parentId":"2"},{"Identifier":"5","Area_Name":"装拆机统计查询","_parentId":"2"},{"Identifier":"6","Area_Name":"产品(分客户群)装拆机统计","_parentId":"2"},{"Identifier":"7","Area_Name":"清单","_parentId":"1"},{"Identifier":"8","Area_Name":"子项一","_parentId":"7"},{"Identifier":"9","Area_Name":"子项二","_parentId":"7"}]}
赞(0) 打赏
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏