Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Dgrid未正确渲染树结构_Javascript_Tree_Dojo_Dgrid_Dstore - Fatal编程技术网

Javascript Dgrid未正确渲染树结构

Javascript Dgrid未正确渲染树结构,javascript,tree,dojo,dgrid,dstore,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"},

我是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树层次结构在替换Rest存储到RequestMemory存储之后工作,并将附加字段hasChildren放入dataset中,以用于mayHaveChildren方法,在Ken Franqueiro提出建议后,还可以获取Children

{“id”:“C1”,“name”:“Test 2”,“quaty”: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;
            }
        });

我认为必须考虑如何构造树数据集,以便覆盖dSturt/Trand方法。 您的数据无效,当您说“未正确渲染”时,缺少一个数量“,它是如何渲染的?它应该如何渲染?当然,看起来您的

getChildren
实现是不正确的,如果您的数据与所有项同时返回,您可能不想使用
Rest
…树应该有三层,其中根(id=T1)后跟第二层(id=C1),最后是第三层(id=S1、S2、S3)。目前它列出了所有没有树的数据。我将尝试用其他方法(如内存存储)替换Rest。您能告诉我当前数据集的getChildren实现有什么问题吗?