Как создать дерево [модель лесного дерева] из JSON...?

Ниже мой JSON. Я пытаюсь создать дерево из этого, я попробовал следующий фрагмент:

require(["dijit/Tree", "dojo/data/ItemFileReadStore", "dijit/tree/ForestStoreModel", "dojo/domReady!"],
        function(Tree, ItemFileReadStore, ForestStoreModel){
    var store = new ItemFileReadStore({
        url: "/om/web/em/tree.json"
 });

    var treeModel = new ForestStoreModel({
        store: store,
        query: {id: 'aid'},
        rootId: "PSS-32",
        rootLabel: "P",
        childrenAttrs: ['eqList']
    });

    var myTree = new Tree({
        model: treeModel
    }, "treeOne");
    myTree.startup();
});

Но это дает мне сообщение об ошибке при загрузке дочерних элементов PSS010010026024 и сообщения: "Не удается прочитать свойство" длина "неопределенных ошибок". Что следует указывать в rootID,rootLabel и childrenAttrs?

[
        {
        "responseStatus": null,
        "entityType": "NODE",
        "aid": "p",
        "id": "p",
        "hsa": null,
        "eqList":[ {
        "responseStatus": null,
        "EId": "5",
        "EGroupId": "1006",
        "aid": "p",
        "additionalInfo": null,
        "eqList": [
        {
        "responseStatus": null,
        "EId": null,
        "EGroupId": null,
        "aid": null,
        "additionalInfo": null,
        "eqList": null,
        "shelfType": null,
        "isEqAvailable": null,
        "id": null,
        "entityType": null,
        "hsa": null,
        "Elist": null
        }
        ],
        "shelfType": null,
        "isEqAvailable": null,
        "id": "p/p",
        "entityType": "E",
        "hsa": "-",
        "Elist": null
        {
        "responseStatus": null,
        "EId": "5",
        "EGroupId": "1006",
        "aid": "p#OCS",
        "EType": "1830pss-ocs",
        "ERelease": "7.0",
        "additionalInfo": null,
        "eqList": [
        {
        "responseStatus": null,
        "EId": null,
        "EGroupId": null,
        "aid": null,
        "EType": null,
        "ERelease": null,
        "additionalInfo": null,
        "eqList": null,
        "shelfType": null,
        "isEqAvailable": null,
        "id": null,
        "entityType": null,
        "hsa": null,
        "Elist": null
        }
        ],
        "shelfType": null,
        "isEqAvailable": null,
        "id": "p/p#OCS",
        "entityType": "E",
        "hsa": "-",
        "Elist": null
        }
        ]
        }
        ]

1 ответ

Атрибут rootID - это идентификатор, который вы хотите присвоить корневому элементу, который будет создан (чтобы вы могли запросить его позже или проверить, находится ли ваше дерево на верхнем уровне). RootLabel - это то, что вы хотите, чтобы метка корневого атрибута была. ChildrenAttrs - это то, как вы указываете Tree, где находятся дочерние узлы определенного узла.

Я не уверен, что вы пытаетесь сделать в своем коде, хотя, поскольку в ваших данных, похоже, нет PSS010010026024, но я бы порекомендовал проверить документацию по API для ForestTreeModel здесь: http://dojotoolkit.org/api/?qs=1.9/dijit/tree/ForestStoreModel

Другие вопросы по тегам