dojo.require("dijit.Tree");
dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dijit.tree.ForestStoreModel");
dojo.require("dojox.data.JsonRestStore");
//TreeStore
var store = new dojo.data.ItemFileWriteStore({
url:'',
labelAttribute: "name"
});
//Tree
var tree = new dijit.Tree({
region: 'leading',
splitter:true,
style: 'width:140px;',
allowMultiState: true,
branchIcons: true,
nodeIcons: true,
openOnClick : true,
//persist: false,
model: new dijit.tree.ForestStoreModel({
store: store,
rootId: "0",
rootLabel: "ROOT",
childrenAttrs: ["children"]
})
});
//节点点击事件
tree .set("onClick", function(item, node, event){
dojo.xhrPost({
url: 'url',
sync: true,
handleAs: 'json',
content: {
pid: item.id //点击的节点ID
},
load:function(response){
var data = response.items;
//加载子节点
for(var i=0;i
identity: data[i].id,
onItem: function(i){
var parent = {
parent: item,
attribute: 'children'
};
store.newItem({
id: data[i].id, //节点ID
name: data[i].name //节点名称
}, parent); //给父节点添加子节点
}
});
}
},
erro:function(error){}
});
});
更多信息请查看 java进阶网 http://www.javady.com