我有一个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是不确定的”。
感谢您的帮助