我有一個dijit的樹代表菜單項, 一些有孩子的,其他的都是葉子節點。道場dijit樹:如何管理父母,孩子和葉節點?
我想知道如何寫這個在JavaScript中,哪個屬性,當我有孩子的正常節點和葉節點使用? 如何寫:在這種情況下使用的文件夾圖標,並在其他葉圖標。
有我的代碼:
<script>
require([
"dojo/_base/window", "dojo/store/Memory",
"dijit/tree/ObjectStoreModel", "dijit/Tree", "dojo",
"dojo/domReady!", "dojo/parser"
], function(win, Memory, ObjectStoreModel, Tree, dojo){
// Create test store, adding the getChildren() method required by ObjectStoreModel
var myStore = new Memory({
data: [
{ id: 1, name: 'Menu', url: 'http://dojotoolkit.org/api/1.6/dijit.Tree', root: true, directory: true },
{ id: 2, name: 'Folder1', url: 'http://dojotoolkit.org/api/1.6/dijit.Tree', parent: 1, directory: false},
{ id: 3, name: 'Leaf1', url: 'http://dojotoolkit.org/api/1.6/dijit.Tree.model', parent: 2 },
{ id: 4, name: 'Leaf2', url: 'http://dojotoolkit.org/api/1.6/dijit.tree.ForestStoreModel', parent: 2 },
...
],
getChildren: function(object){
return this.query({parent: object.id});
}
});
// Create the model
var myModel = new ObjectStoreModel({
store: myStore,
query: {root: true}
});
// Create the Tree, specifying an onClick method
(new Tree({
model: myModel,
getIconClass:function(item, opened){
return myStore.getValue(item, 'directory') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "dijitLeaf";
},
onClick: function(item){
// Get the URL from the item, and navigate to it
// location.href = item.url;
//parent.getElementById('central').src = item.url;
parent.central.location.href = item.url;
}
})).placeAt(win.body()).startup();
});
</script>
但它不工作。
我試圖與第一和內部的MyStore第二項的目錄屬性,但加載getIconClass時,我得到一個錯誤:「的MyStore是不確定的」。
感謝您的幫助