前端之家收集整理的这篇文章主要介绍了
有关dojo中dijit/Tree的操作增、删、修改,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
/*创建对象树*/
createTree.js页面
define(["dojo/aspect","dijit/registry","dijit/tree/ObjectStoreModel","dijit/Tree","dojo/store/Memory","dojo/store/Observable","dojo/request","dojo/domReady!"
],function(aspect,registry,ObjectStoreModel,Tree,Memory,Observable,request) {
var treeDataStore = new Memory({
data : [{id : "mainTreeId",name : "类别"}],getChildren: function(obj) {
return this.query({parent: obj.id});
}
});
aspect.around(treeDataStore,"put",function(originalPut){
return function(obj,options){
if(options && options.parent){
obj.parent = options.parent.id;
}
return originalPut.call(treeDataStore,obj,options);
};
});
treeDataStore = new Observable(treeDataStore);
var treeStoreModel = new ObjectStoreModel({
store: treeDataStore,query: {id: "mainTreeId"},labelAttr: "name",labelType: "html"
});
var myTree= new Tree({
id: "myTree",model: treeStoreModel
},"transformTree");
transformTree.startup();
});
//增加、删除、修改树节点信息窗口
operateTree.js页面
//增加子节点
treeDataStore.add({id : "Id",name : "Name",parent: "mainTreeId"});
//删除选中的树节点
treeDataStore.remove(selectedItem.id);
//修改树中的转换name
var stores =(registry.byId("myTree").model.store);
var storeObj=stores.get(registry.byId("myTree").selectedItem.id.toString());
storeObj.name = "newName";
stores.put(storeObj);
原文链接:https://www.f2er.com/dojo/291218.html