0

我是 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 在用户交互之前看起来很平坦

提前感谢和感谢。

4

1 回答 1

0

在将 Rest 存储替换为 RequestMemory 存储并将附加字段 hasChildren 放入数据集中以用于 mayHaveChildren 方法和 getChildren 后,我终于使 Dgrid Tree 层次结构工作,得到 Ken Franqueiro 的建议。

{"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 方法。

于 2015-11-03T05:37:30.953 回答