Dgrid无法正确呈现树结构

时间:2015-11-02 17:18:08

标签: javascript tree dojo dgrid dstore

我是JavaScript,dojo dgrid,dstore的初学者,仍然很难正确覆盖商店的属性方法:

我的数据结构:

[{"id":"T1","name":"Test","desc":"Rectangular 1",qty":null,"parent":null},    
{"id":"C1","name":"Test 2","qty":0.0,"parent":"T1"},    
{"id":"S1","name":"Test 3","qty":6.0,"parent":"C1"},    
{"id":"S2","name":"Test 4","qty":6.0,"parent":"C1"},    
{"id":"S3","name":"Test 5","qty":6.0,"parent":"C1"}
]


        var StandardGrid = declare([Grid, Keyboard, Selection, Selector, Editor, dgridTree]);
        var CustomStore= declare([Rest, dstoreTree]);

        var myStore = new CustomStore({
            target: "./data.json",
            idProperty: "id",
            getRootCollection: function () {
                return this.root.filter({ parent: null });                  
            },
            getChildren: function (object) {
                return object.parent = object.id;
            },
            mayHaveChildren: function (object) {
                return object.parent == null;
            },
        });

        var treeGrid = window.treeGrid = new StandardGrid({
            collection: myStore.getRootCollection(),
            columns: [
                { renderExpando: true, label: "Name", field: "name", sortable: false },
                { label: "Quantity", field: "qty" },
            ]
        }, "treeGrid");

        treeGrid.startup();

我也尝试参考以下链接,但仍然无法弄清楚: dgrid 0.4.0 tree looks flat before user interacts

提前感谢并感谢。

1 个答案:

答案 0 :(得分:0)

我终于在将Substiture Rest存储到RequestMemory存储之后使Dgrid Tree层次结构工作,并将其他字段hasChildren放入mayHaveChildren方法中使用的数据集中,并在Ken Franqueiro建议之后输入getChildren。

{“id”:“C1”,“name”:“Test 2”,“qty”:0.0,“parent”:“T1”,“hasChidlren”:true }

        var StandardGrid = declare([Grid, Keyboard, Selection, Selector, Editor, Tree]);
        var MemoryTreeStore = declare([RequestMemory, TreeStore]);

        var myStore = new MemoryTreeStore({
            target: "./data.json",
            idProperty: "id",
            getRootCollection: function () {
                return this.root.filter({parent: null});                    
            },
            getChildren: function (object) {
                return this.root.filter({parent: object.id});
            },
            mayHaveChildren: function (object) {
                return object.parent == null || object.hasChildren == true;
            }
        });

我认为必须考虑如何构建树数据集以便覆盖dstore / Tree方法。