easyui treegrid 动态展开数据(暂记)

 ClassifyAdminSynMsgSvr.GetCLFLList("<%=CurUTag %>", 1, "", function (ret) {
                    //console.log(ret);
                    //console.log(ret._Items);
                    var zhdata = ret._Items;
                    var fileds = "FLID,DEEP,FLMC";
                    //获取已转为符合treegrid的json的对象
                    var nodes = ConvertToTreeGridJson("FLID", "FLID", "DEEP", fileds);
                    //
                    $(ret._Items).each(function (i, o) {
                        $.extend(o, { children: []})
                    });
                    console.log(JSON2.stringify(nodes));
                    $('#ClassifyTree').treegrid({
                        data: ret._Items,
                        idField: 'FLID', 
                        treeField: 'FLID',    
                        width: '33%',
                        height: '500',
                        pagination: false, rownumbers: true, singleSelect: true,
                        toolbar: [{
                            iconCls: 'icon-edit',
                            text: '编辑',
                            handler: function () {
                                $("#dlg").dialog("open");  
                            }
                        }, {
                            iconCls: 'icon-add',
                            text: '增加',
                            handler: function () {
                                $("#dlg").dialog("open");
                            }
                        }, {
                            iconCls: 'icon-no',
                            text: '删除',
                            handler: function () { }
                        }],
                        loadFilter: myLoadFilter,
                        onClickRow: function (index, row) {
                            console.log(row);
                            //getGetFLMXList(row["FLID"]);
                            //GetFLPrtList(row["FLID"]);
                        },
                        columns: [[
                            { field: 'FLID', title: '材料编号', width: '40%', align: 'left' },
                            { field: 'FLMC', title: '材料分类', width:'50%', align: 'left' },
                        ]]
                    });
                });
function myLoadFilter(data, parentId) {
                function setData() {
                    var todo = [];
                    for (var i = 0; i < data.length; i++) {
                        todo.push(data[i]);
                    }
                    while (todo.length) {
                        var node = todo.shift();
                        if (node.children) {
                            node.state = 'closed';
                            node.children1 = node.children;
                            node.children = undefined;
                            todo = todo.concat(node.children1);
                        }
                    }
                }
                setData(data);
                var tg = $(this);
                var opts = tg.treegrid('options');
                opts.onBeforeExpand = function (row) {
                   var secondData= ClassifyAdminSynMsgSvr.GetCLFLList("<%=CurUTag %>", 2, row.FLID);

                   if (secondData && !row.children) {
                        tg.treegrid('append', {
                            parent: row[opts.idField],
                            data: secondData._Items
                        });
                        row.children1 = undefined;
                    }
                    return row.children1 == undefined;
                };
                return data;
            }
<link href="../../Scripts/jquery-easyui-1.5/themes/default/easyui.css" rel="stylesheet" />
    <link href="../../Scripts/jquery-easyui-1.5/themes/icon.css" rel="stylesheet" />
    <script src="../../Scripts/jquery.min.js"></script>
    <script src="../../Scripts/jquery-easyui-1.5/jquery.easyui.min.js"></script>
    <script src="../../Scripts/jquery-easyui-1.5/locale/easyui-lang-zh_CN.js"></script>
posted @ 2018-01-04 20:43  三瑞  阅读(356)  评论(0编辑  收藏  举报