当前位置 : 主页 > 网页制作 > Dojo >

有关dojo中dijit/Tree的操作增、删、修改

来源:互联网 收集:自由互联 发布时间:2021-06-15
/*创建对象树*/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, ObjectSt
/*创建对象树*/
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);
网友评论