2014-04-22 32 views
0

以下是我的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 
     } 
     ] 
     } 
     ] 

回答

0

的rootID屬性是你想給將要創建(這樣你可以,如果你的樹以後查詢,或檢查根項目什麼ID是在頂層)。rootLabel是你想要的根屬性的標籤。孩子們是如何喲你告訴樹特定節點的孩子。

我不知道你想在你的代碼,這樣做雖然因爲您的數據似乎並不具有PSS010010026024它什麼,但我會建議您檢查出的ForestTreeModel這裏的API文檔:http://dojotoolkit.org/api/?qs=1.9/dijit/tree/ForestStoreModel