简体   繁体   English

Dijit树未按预期呈现

[英]Dijit Tree not rendering as expected

I am trying to get a json data render a dojo tree. 我正在尝试使json数据呈现道场树。

You can see what I am doing at http://jsfiddle.net/F53Ge/38/ 您可以在http://jsfiddle.net/F53Ge/38/中看到我在做什么

                                   require(["dojo/parser","dojo/json","dojo/store/Memory","dijit/tree/ObjectStoreModel","dijit/Tree", "dojo/window"], function              (parser,json,Memory,ObjectStoreModel,Tree,win) {



var data = [{"id":"root","team":[{"teamId":1,"teamname":"JMK_TEST_1","parentteamId":0,"associatedList":[{"type":"9117","number":"1011D1P"}]},{"teamId":174,"teamName":"JJG_PARENT_3","parentteamId":0,"associatedList":[{"type":"8205","number":"062072T"}]},{"teamId":172,"teamName":"JJG_PARENT_1","parentteamId":0,"subteamsList":[{"teamId":175,"teamName":"JJG_Subteam_1","parentteamId":172,"associatedList":[{"type":"8720","number":"12345"}]},{"teamId":176,"teamName":"JJG_Subteam_2","parentteamId":172,"associatedList":[{"type":"8720","number":"12345"}]}],"associatedList":[{"type":"7945","number":"KQZGTNC"}]},{"teamId":221,"teamName":"JJG_Parent_4","parentteamId":0,"subteamsList":[{"teamId":222,"teamName":"JJG_Subteam_4_1","parentteamId":221,"associatedList":[{"type":"9117","number":"10E7683"},{"type":"9119","number":"514DDB2"},{"type":"8233","number":"102FE9P"},{"type":"7978","number":"KDGYKLL"},{"type":"7978","number":"99A9880"}]}]},{"teamId":106,"teamName":"JMK_TEST","parentteamId":0,"subteamsList":[{"teamId":107,"teamName":"JMK_TEST1","parentteamId":106,"subteamsList":[{"teamId":173,"teamName":"JJG_PARENT_2","parentteamId":107,"subteamsList":[{"teamId":178,"teamName":"JJG_Subteam_2_1","parentteamId":173,"associatedList":[{"type":"9117","number":"10E7683"}]}],"associatedList":[{"type":"7945","number":"KQZGTNC"}]}]}]}]}];


var store = new Memory({
    data: data,
    getChildren: function(object){
        return object.team || [];
    }
});

  var model = new ObjectStoreModel({
store: store,
   query: { id:'root' },
    mayHaveChildren: function (item) {
        return "subteamsList" in item;
    }
});

var tree = new Tree({
    model: model,
    showRoot: false,
    autoExpand: true,
    persist: false,
    onClick: function (item, treeNode, e) {
        selectednodeid = this.selectedNode;
        win.scrollIntoView(selectednodeid);
        alert(selectednodeid);
    }
},"oopt_list");
tree.startup();


 });

First I am not see children nodes and also do not know how to pass the label as it shows undefined for the list. 首先,我看不到子节点,也不知道如何传递标签,因为标签显示的列表未定义。

Any help is appreciated. 任何帮助表示赞赏。

Also let me know if I should use the ForestModel instead. 还请让我知道是否应该使用ForestModel。 Basically I am trying to show the json data in a tree hireachy and want to know which node the user clicked so I can do some action based on that. 基本上,我试图在树状目录中显示json数据,并想知道用户单击了哪个节点,因此我可以基于此执行一些操作。

Regards BumbleBee 问候大黄蜂

To define which property should be used as label, you need to define 'labelAttr' on model. 要定义应将哪个属性用作标签,您需要在模型上定义“ labelAttr”。

The reason, why you do not see the child nodes is, that you store is missing idProperty on Store. 之所以看不到子节点,是因为您存储的商店缺少idProperty。 (or you have different id property on root item 'id' and different on other items 'teamId'). (或者您在根项“ id”上具有不同的id属性,而在其他项“ teamId”上具有不同的属性)。

Using ObjectStoreModel instead of ForestModel is correct. 使用ObjectStoreModel代替ForestModel是正确的。 You are using Memory store, which is implementaion of new dojo/store API. 您正在使用内存存储,它是新的dojo / store API的实现。 (ForestModel should be used only with older dojo/data API) (ForestModel应该仅与较旧的dojo / data API一起使用)

See your sample updated here http://jsfiddle.net/F53Ge/42/ 在这里查看您的示例更新http://jsfiddle.net/F53Ge/42/

require(["dojo/parser","dojo/json","dojo/store/Memory","dijit/tree/ObjectStoreModel","dijit/    Tree", "dojo/window"], function (parser,json,Memory,ObjectStoreModel,Tree,win) {



var data = [{"teamId":"root","subteamsList":[{"teamId":1,"teamName":"JMK_TEST_1","parentteamId":0,"associatedList":[{"type":"9117","number":"1011D1P"}]},{"teamId":174,"teamName":"JJG_PARENT_3","parentteamId":0,"associatedList":[{"type":"8205","number":"062072T"}]},{"teamId":172,"teamName":"JJG_PARENT_1","parentteamId":0,"subteamsList":[{"teamId":175,"teamName":"JJG_Subteam_1","parentteamId":172,"associatedList":[{"type":"8720","number":"12345"}]},{"teamId":176,"teamName":"JJG_Subteam_2","parentteamId":172,"associatedList":[{"type":"8720","number":"12345"}]}],"associatedList":[{"type":"7945","number":"KQZGTNC"}]},{"teamId":221,"teamName":"JJG_Parent_4","parentteamId":0,"subteamsList":[{"teamId":222,"teamName":"JJG_Subteam_4_1","parentteamId":221,"associatedList":[{"type":"9117","number":"10E7683"},{"type":"9119","number":"514DDB2"},{"type":"8233","number":"102FE9P"},{"type":"7978","number":"KDGYKLL"},{"type":"7978","number":"99A9880"}]}]},{"teamId":106,"teamName":"JMK_TEST","parentteamId":0,"subteamsList":[{"teamId":107,"teamName":"JMK_TEST1","parentteamId":106,"subteamsList":[{"teamId":173,"teamName":"JJG_PARENT_2","parentteamId":107,"subteamsList":[{"teamId":178,"teamName":"JJG_Subteam_2_1","parentteamId":173,"associatedList":[{"type":"9117","number":"10E7683"}]}],"associatedList":    [{"type":"7945","number":"KQZGTNC"}]}]}]}]}];


    var store = new Memory({
        data: data,
        idProperty:"teamId",
        getChildren: function(object){
            return object.subteamsList || [];
        }
    });

   var model = new ObjectStoreModel({
    store: store,
       query: { teamId:'root' },
        mayHaveChildren: function (item) {
            console.log("may",item)
            return "subteamsList" in item;
        },labelAttr :"teamName"
    });
    var tree = new Tree({
        model: model,
        showRoot: false,
        autoExpand: true,
        persist: false,
        onClick: function (item, treeNode, e) {
            selectednodeid = this.selectedNode;
            win.scrollIntoView(selectednodeid);
            alert(selectednodeid);
        }
    },"oopt_list");
    tree.startup();


});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM