DOJO中没有显示树

时间:2012-10-03 15:14:46

标签: javascript dojo digit

我是DOJO 1.6的新手

我尝试显示带有子文件夹的树。

dojo.require("dojo.data.ItemFileWriteStore");
            dojo.require("dijit.form.Button");
            dojo.require("dijit.tree.TreeStoreModel");
dojo.require("dojo.store.Memory");
dojo.require("dijit.Tree");
            dojo.addOnLoad(function() {
                 // Create test store, adding the getChildren() method required by ObjectStoreModel
        var data =  [ { id: 1, name: "answerTypeLabel",                 type:'scenario',    children:[{_reference: 2}]},
                       { id: 2, name: "acceptRequestLabel",             type:'paragraph',   data: "acceptRequestLabel"},
                       { id: 3, name: "rejectRequestLabel",             type:'scenario',    children:[{_reference: 5},{_reference: 6}]},
                       { id: 4, name: "MoreInformationLabel",       type:'scenario',    children:[{_reference: 7},{_reference: 8}]},
                       { id: 5, name: "rejectRequestStatusLabel",   type:'paragraph',   data: "rejectRequestStatusLabel"},
                       { id: 6, name: "rejectRequestNotCoveredLabel", type:'paragraph',     data: "rejectRequestNotCoveredLabel" },
                       { id: 7, name: "MoreInformationDocumentLabel", type:'paragraph',     data: "MoreInformationDocumentLabel"},
                       { id: 8, name: "MoreInformationDataLabel",   type:'paragraph',   data: "MoreInformationDataLabel"}
                     ];
         // Building the store object
        var sortableStore = new dojo.data.ItemFileWriteStore({
                    data: {
                        identifier: 'id',
                        label: 'name',
                        items: data 
                    },
                    });
        // building the model           
        var model = new dijit.tree.ForestStoreModel({

                    store: sortableStore, 
            query: { 
                id: "*" 
            }, 
            rootId: "root", 
            rootLabel: "sorting of tree"

        }); 
        // Building the tree            
        var tree = new dijit.Tree({

            model:model,
            'class': "tundra" 
        },
        "resourceTree");

            });

output of code

这里Id 1是Id 1的子节点,因此显示Id 2时必须在Id 1内。 但是这里Id 2出现在id 1中,也出现在id 1的同一级别上。(所有子id都有重复)。 这是id 2,5,6,7,8的情况。

我想删除重复内容。

Ouptput应该像

correctoutput should be like this

1 个答案:

答案 0 :(得分:1)

原因是你将一个非层次存储应用到一棵树上,该树不应该显示父母作为兄弟的根目录。

要“修复”此问题,model query引用的ID需要才能获得匹配

在您的数据情况下,看起来type:'paragraph'应该是离开的。因此,请将查询设置为与type:'scenario'匹配,而不是当前的“id:”*“'

    var model = new dijit.tree.ForestStoreModel({

                store: sortableStore, 
        query: { 
            type:'scenario'
        }, 
        rootId: "root", 
        rootLabel: "sorting of tree"

    });