Datatree

来自ling
跳转至: 导航搜索

判断树节点类型

var currentNode = self.get("currentNode"), type = currentNode
			.get("bindingConfig.name");
    var id = currentNode.get("data.id");

动态设置树的当前值

// @Bind #dataTreeKnowledge.onReady
!function(self, arg, dataTypeKnowledge, dataTypeStep,dataTypeAnswer) {
	dorado.DataPath.registerInterceptor("currentKnowledge",function(data) {
		var entity = self.get("currentNode.data");
		return (entity && entity.dataType == dataTypeKnowledge) ? entity: null;
	}, function(dataType) {
		return dataTypeKnowledge;
	});
	dorado.DataPath.registerInterceptor("currentStep", function(data) {
		var entity = self.get("currentNode.data");
		return (entity && entity.dataType == dataTypeStep) ? entity : null;
	}, function(dataType) {
		return dataTypeStep;
	});
	dorado.DataPath.registerInterceptor("currentAnswer", function(data) {
		var entity = self.get("currentNode.data");
		return (entity && entity.dataType == dataTypeAnswer) ? entity : null;
	}, function(dataType) {
		return dataTypeAnswer;
	});
};

配合以下代码

// @Bind #dataTreeKnowledge.onCurrentChange
!function(self, arg) {
	var dataSetKnowledge = view.id("dataSetKnowledge");
	var currentknowledge = dataSetKnowledge.getData("!currentKnowledge");
	var currentStep = dataSetKnowledge.getData("!currentStep");
	var currentAnswer = dataSetKnowledge.getData("!currentAnswer");
	if (currentknowledge) {// 选中的是模块节点
		view.id("fieldSetKnowledge").set("visible", true);
		view.id("fieldSetStep").set("visible", false);
		view.id("fieldSetAnswer").set("visible", false);
		view.id("buttonAddSubKnowledge").set("disabled", false);
		view.id("buttonAddStepSub").set("disabled", false);
		view.id("buttonAddAnswerSub").set("disabled", true);		
	} else if (currentStep) {// 选中的是步骤节点
		view.id("fieldSetKnowledge").set("visible", false);
		view.id("fieldSetStep").set("visible", true);	
		view.id("fieldSetAnswer").set("visible", false);
		view.id("buttonAddSubKnowledge").set("disabled", true);
		view.id("buttonAddStepSub").set("disabled", false);
		view.id("buttonAddAnswerSub").set("disabled", false);	
	} else if (currentAnswer) {// 选中的是步骤节点
		view.id("fieldSetKnowledge").set("visible", false);
		view.id("fieldSetStep").set("visible", false);
		view.id("fieldSetAnswer").set("visible", true);
		view.id("buttonAddSubKnowledge").set("disabled", true);
		view.id("buttonAddStepSub").set("disabled", true);
		view.id("buttonAddAnswerSub").set("disabled", true);
	}
 
};

或者直接判断

	var currentCategoryNode = treeExamples.get("currentNode");
	if (currentCategoryNode.get("bindingConfig.name") == "Example")
		currentCategoryNode = currentCategoryNode.get("parent");
	if (category == currentCategoryNode.get("data")) {
		dorado.MessageBox.alert("请选择一个不同的分类。");
		return;
	}

树节点渲染(高级)

// @Bind #treeExamples.onRenderNode
!function(arg) {
	var node = arg.node, data = node.get("data"), xCreateConfig = [];
	arg.dom.style.fontWeight = (data.get("hot") ? "bold" : "");

	if (node.get("bindingConfig.name") == "category") {
		xCreateConfig.push({
			tagName : "SPAN",
			contentText : node.get("label")
		});
		xCreateConfig.push({
			tagName : "SPAN",
			contentText : "(" + data.get("childCount") + ")",
			style : "margin-left: 2px; color: gray"
		});
		if (data.get("new")) {
			xCreateConfig.push({
				tagName : "IMG",
				src : $url(">images/new.gif"),
				style : "position: relative; left: 4px; top: 4px"
			});
		}
	} else {
		if (data.get("new")) {
			xCreateConfig.push({
				tagName : "SPAN",
				contentText : node.get("label")
			});
			xCreateConfig.push({
				tagName : "IMG",
				src : $url(">images/new.gif"),
				style : "position: relative; left: 4px; top: 4px"
			});
			xCreateConfig.push({
				tagName: "A",
				href: "version.view.ManageBusinessDictView.ling?businessDictId=" + arg.data.get("businessDictId"),
				content: "业务词典表维护"
			});
		}
	}

	if (xCreateConfig.length) {
		$(arg.dom).empty().xCreate(xCreateConfig);
	} else {
		arg.processDefault = true;
	}
}

操作树节点

// @Controller

// @Bind #buttonCollapseAll.onClick
!function(treeGrid) {
	function collapse(nodes) {
		nodes.each(function(node) {
			collapse(node.get("nodes"));
			if (node.get("expanded"))
				node.collapse();
		});
	}

	collapse(treeGrid.get("nodes"));
}

// @Bind #buttonExpandAll.onClick
!function(treeGrid) {
	function expand(nodes) {
		nodes.each(function(node) {
			if (!node.get("expanded"))
				node.expand();
			expand(node.get("nodes"));
		});
	}

	expand(treeGrid.get("nodes"));
}

// @Bind #buttonSelectAll.onClick
!function(treeGrid) {
	function select(nodes) {
		nodes.each(function(node) {
			select(node.get("nodes"));
			node.set("checked", true);
		});
	}

	select(treeGrid.get("nodes"));
}

// @Bind #buttonUnselectAll.onClick
!function(treeGrid) {
	function unselect(nodes) {
		nodes.each(function(node) {
			unselect(node.get("nodes"));
			node.set("checked", false);
		});
	}

	unselect(treeGrid.get("nodes"));
}

// @Bind #buttonShowSelection.onClick
!function(treeGrid) {
	var nodes = treeGrid.getCheckedNodes(), message;
	if (nodes && nodes.length) {
		var names = [];
		nodes.each(function(data) {
			names.push(data.get("data.firstName"));
		});
		message = names.join("\n");
	} else {
		message = "未选中任何节点!";
	}
	dorado.MessageBox.alert(message);
}

// @Bind #buttonHighlightCurrent.onClick
!function(treeGrid) {
	var currentNode = treeGrid.get("currentNode");
	if (!currentNode) {
		throw new dorado.Exception("请先点中一个树节点!");
	}

	treeGrid.highlightItem();
}

// @Bind #buttonAppendChild.onClick
!function(treeGrid) {
	var currentNode = treeGrid.get("currentNode");
	if (!currentNode) {
		throw new dorado.Exception("请先点中一个树节点!");
	}

	var currentEntity = currentNode.get("data");
	currentNode.expandAsync(function() {
		currentEntity.createChild("underlings", {
			firstName : "<First Name>",
			lastName : "<Last Name>"
		});
	});
}

// @Bind #buttonInsertChild.onClick
!function(treeGrid) {
	var currentNode = treeGrid.get("currentNode");
	if (!currentNode) {
		throw new dorado.Exception("请先点中一个树节点!");
	}

	var currentEntity = currentNode.get("data");
	currentNode.expandAsync(function() {
		currentEntity.get("underlings").insert({
			firstName : "<First Name>",
			lastName : "<Last Name>"
		}, "before");
	});
}

// @Bind #buttonAppendBrother.onClick
!function(treeGrid) {
	var currentNode = treeGrid.get("currentNode");
	if (!currentNode) {
		throw new dorado.Exception("请先点中一个树节点!");
	}

	var currentEntity = currentNode.get("data");
	currentEntity.createBrother({
		firstName : "<First Name>",
		lastName : "<Last Name>"
	});
}

// @Bind #buttonInsertBrother.onClick
!function(treeGrid) {
	var currentNode = treeGrid.get("currentNode");
	if (!currentNode) {
		throw new dorado.Exception("请先点中一个树节点!");
	}

	var currentEntity = currentNode.get("data");
	currentEntity.parent.insert({
		firstName : "<First Name>",
		lastName : "<Last Name>"
	}, "before", currentEntity);
}

// @Bind #buttonDelete.onClick
!function(treeGrid) {
	var currentEntity = treeGrid.get("currentEntity");
	if (!currentEntity) {
		throw new dorado.Exception("请先点中一个树节点!");
	}

	currentEntity.remove();
}

// @Bind #buttonMoveUp.onClick
!function(treeGrid) {
	var currentEntity = treeGrid.get("currentNode.data");
	if (!currentEntity) {
		throw new dorado.Exception("请先点中一个树节点!");
	}

	var previous = currentEntity.getPrevious();
	if (!previous) {
		throw new dorado.Exception("当前节点已是父节点下的第一个树节点!");
	}
	currentEntity.parent.insert(currentEntity, "before", previous);
	treeGrid.set("currentEntity", currentEntity);
}

// @Bind #buttonMoveDown.onClick
!function(treeGrid) {
	var currentEntity = treeGrid.get("currentNode.data");
	if (!currentEntity) {
		throw new dorado.Exception("请先点中一个树节点!");
	}

	var next = currentEntity.getNext();
	if (!next) {
		throw new dorado.Exception("当前节点已是父节点下的最后一个树节点!");
	}
	currentEntity.parent.insert(currentEntity, "after", next);
	treeGrid.set("currentEntity", currentEntity);
}

// @Bind #buttonUpgrade.onClick
!function(treeGrid) {
	var currentNode = treeGrid.get("currentNode");
	if (!currentNode) {
		throw new dorado.Exception("请先点中一个树节点!");
	}
	if (currentNode.get("level") == 1) {
		throw new dorado.Exception("当前节点顶层树节点!");
	}

	var currentEntity = currentNode.get("data");
	var parentEntity = currentNode.get("parent.data");
	parentEntity.parent.insert(currentEntity, "after", parentEntity);
	treeGrid.set("currentEntity", currentEntity);
}

决策树代码

window.iFrameSelectStepForAnswer;
// @Bind view.onReady
!function(self, arg) {
	window.iFrameSelectStepForAnswer=view.id("iFrameSelectStepForAnswer");
	window.$CurrentOperation;
	window.$CurrentOperationStep;
	window.createTopNodeKnowledge = function() {
		var dataSetKnowledge = view.id("dataSetKnowledge");
		var dataTreeKnowledge = view.id("dataTreeKnowledge");
		var newEntity=dataSetKnowledge.getData().createChild({
			name : "新分配"
		});
		dataTreeKnowledge.set("currentEntity", newEntity);
	};

	window.createSubNodeKnowledge = function() {
		var dataSetKnowledge = view.id("dataSetKnowledge");
		var dataTreeKnowledge = view.id("dataTreeKnowledge");
		var currentKnowledge = dataSetKnowledge.getData("!currentKnowledge");
		var currentStep = dataSetKnowledge.getData("!currentStep");
		var currentAnswer = dataSetKnowledge.getData("!currentAnswer");
		

		var currentNode = dataTreeKnowledge.get("currentNode");
		if (currentNode) {
			if (!currentNode.get("expanded")) {
				currentNode.expand();
			}
		}

		if (currentKnowledge) {// 选中的是专题节点
			if(currentKnowledge.get("id")){
				var newEntity = currentKnowledge.createChild("knowledges", {
					parentId : currentKnowledge.get("id"),
					name : "新专题"
				});
				dataTreeKnowledge.set("currentEntity", newEntity);
			}else{
				dorado.MessageBox.alert("请先保存后再添加子节点");
			}			
		} else if (currentStep) {// 选择的是步骤节点
			dorado.MessageBox.alert("请先选中一个分配节点或专题节点");
		}else if(currentAnswer){//选择的是答案节点
			dorado.MessageBox.alert("请先选中一个步骤节点");
		} else {// 没有任何节点被选中,树为空
			dataSetKnowledge.getData().createChild({
				name : "新分配"
			});
		}
	};
	window.createSubNodeStep = function() {
		var dataSetKnowledge = view.id("dataSetKnowledge");
		var dataTreeKnowledge = view.id("dataTreeKnowledge");
		var currentknowledge = dataSetKnowledge.getData("!currentKnowledge");
		var currentStep = dataSetKnowledge.getData("!currentStep");
		var currentAnswer = dataSetKnowledge.getData("!currentAnswer");

		var currentNode = dataTreeKnowledge.get("currentNode");
		if (currentNode) {
			if (!currentNode.get("expanded")) {
				currentNode.expand();
			}
		}

		if (currentknowledge) {// 选中的是模块节点
			if(currentknowledge.get("id")){
				var newEntity = currentknowledge.createChild("steps", {
					knowledgeId : currentknowledge.get("id"),
					name : "新步骤"
				});
				// dataTreeKnowledge.get("currentNode").expand();
				dataTreeKnowledge.set("currentEntity", newEntity);
			}else{
				dorado.MessageBox.alert("请先保存后再添加子节点");
			}
			
		} else if (currentStep) {// 选中的是步骤节点
			// currentExample.createBrother(data);
			if(currentStep.get("id")){
				var newEntity = currentStep.createChild("steps", {
					parentId : currentStep.get("id"),
					name : "新子步骤"
				});
				dataTreeKnowledge.get("currentNode").expand();
				dataTreeKnowledge.set("currentEntity", newEntity);
			}else{
				dorado.MessageBox.alert("请先保存后再添加子节点");
			}
		}else if(currentAnswer){//选择的是答案节点
			dorado.MessageBox.alert("请先选中一个步骤节点");
		} else {// 什么都没选中
			dorado.MessageBox.alert("请先选中一个节点");
		}
	};
	window.createSubNodeAnswer = function() {
		var dataSetKnowledge = view.id("dataSetKnowledge");
		var dataTreeKnowledge = view.id("dataTreeKnowledge");
		var currentknowledge = dataSetKnowledge.getData("!currentKnowledge");
		var currentStep = dataSetKnowledge.getData("!currentStep");
		var currentAnswer = dataSetKnowledge.getData("!currentAnswer");
		
		var currentNode = dataTreeKnowledge.get("currentNode");
		if (currentNode) {
			if (!currentNode.get("expanded")) {
				currentNode.expand();
			}
		}

		if (currentknowledge) {// 选中的是模块节点
			dorado.MessageBox.alert("请先选中一个步骤节点");
		} else if (currentStep) {// 选中的是步骤节点
			if(currentStep.get("id")){
				var newEntity = currentStep.createChild("answers", {
					stepId : currentStep.get("id"),
					name : "新可选答案"
				});
				// dataTreeKnowledge.get("currentNode").expand();
				dataTreeKnowledge.set("currentEntity", newEntity);
			}else{
				dorado.MessageBox.alert("请先保存后再添加子节点");
			}
		}else if(currentAnswer){//选择的是答案节点
			// currentExample.createBrother(data);
			if(currentAnswer.get("id")){
				var newEntity = currentAnswer.createChild("answers", {
					parentId : currentAnswer.get("id"),
					name : "新可选子答案"
				});
				dataTreeKnowledge.get("currentNode").expand();
				dataTreeKnowledge.set("currentEntity", newEntity);
			}else{
				dorado.MessageBox.alert("请先保存后再添加子节点");
			}			
		} else {// 什么都没选中
			dorado.MessageBox.alert("请先选中一个节点");
		}
	};
	window.deleteNode = function() {
		var currentEntity = view.id("dataTreeKnowledge").get("currentEntity");
		var action = view.id("updateActionKnowledge");
		if (currentEntity) {
			var currentNode = view.id("dataTreeKnowledge").get("currentNode");
			if (!currentNode.get("expanded")) {
				currentNode.expand();
			}
			dorado.MessageBox.show({
				title : "提示",
				icon : dorado.MessageBox.INFO_ICON,
				message : "您真的要删除当前节点吗?",
				buttons : [ "yes", "no" ],
				detailCallback : function(buttonId) {
					if (buttonId == "yes") {
						currentEntity.remove();
						action.execute();
					}
				}
			});
		} else {
			dorado.MessageBox.show({
				title : "操作错误",
				icon : dorado.MessageBox.ERROR_ICON,
				message : "请选中一个节点节点后再进行此操作!",
				buttons : [ "ok" ]
			});
		}
	};
};
window.saveAlldata=function(){
	var action = view.id("updateActionKnowledge");
//	dorado.MessageBox.show({
//		title : "提示",
//		icon : dorado.MessageBox.INFO_ICON,
//		message : "确定要保存当前数据?",
//		buttons : [ "yes", "no" ],
//		detailCallback : function(buttonId) {
//			if (buttonId == "yes") {
				action.execute(function() {
					
				});
//			} else {
//
//			}
//		}
//	});
};
// @Bind #buttonAddKnowledge.onClick
!function(self, arg) {
	window.createTopNodeKnowledge();
};

// @Bind #buttonAddSubKnowledge.onClick
!function(self, arg) {
	window.createSubNodeKnowledge();

};
// @Bind #buttonAddStepSub.onClick
!function(self, arg) {
	window.createSubNodeStep();

};
//@Bind #buttonAddAnswerSub.onClick
!function(self, arg) {
	window.createSubNodeAnswer();

};
// @Bind #buttonDelete.onClick
!function(self, arg) {
	window.deleteNode();

};

// @Bind #dataTreeKnowledge.onDragStop
!function(self, arg, updateActionKnowledge,dataTypeKnowledge, dataTypeStep,dataTypeAnswer) {
	var draggingInfo = arg.draggingInfo;
	try {	
		var sourceObject = draggingInfo.get("object");
		var targetObject = draggingInfo.get("targetObject");
		var sourceEntity = sourceObject.get("data");
		
		if(self==targetObject){
			throw new Error("类型不符合");
		}
		var targetEntity = targetObject.get("data");
		
		var accept=true;
		
		if((sourceEntity&&sourceEntity.dataType == dataTypeKnowledge)
				&&(targetEntity&&targetEntity.dataType == dataTypeKnowledge))
		{//Knowledge-->Knowledge
			sourceEntity.set("parentId", targetEntity.get("id"));
			//window.$CurrentOperation = "DragTreeNode";
		}
		else if((sourceEntity&&sourceEntity.dataType == dataTypeStep)
				&&(targetEntity&&targetEntity.dataType == dataTypeStep))
		{//Step-->Step
			sourceEntity.set("parentId", targetEntity.get("id"));
			sourceEntity.set("knowledgeId", null);
			//window.$CurrentOperation = "DragTreeNode";
		}
		else if((sourceEntity&&sourceEntity.dataType == dataTypeAnswer)
				&&(targetEntity&&targetEntity.dataType == dataTypeAnswer))
		{//Answer-->Answer
			sourceEntity.set("parentId", targetEntity.get("id"));
			sourceEntity.set("stepId", null);
			//window.$CurrentOperation = "DragTreeNode";
		}
		else if((sourceEntity&&sourceEntity.dataType == dataTypeAnswer)
				&&(targetEntity&&targetEntity.dataType == dataTypeStep))
		{//Answer-->Step
			sourceEntity.set("stepId", targetEntity.get("id"));
			sourceEntity.set("parentId", null);
			//window.$CurrentOperation = "DragTreeNode";
		}
		else if((sourceEntity&&sourceEntity.dataType == dataTypeStep)
				&&(targetEntity&&targetEntity.dataType == dataTypeKnowledge))
		{//Step-->Knowledge
			sourceEntity.set("knowledgeId", targetEntity.get("id"));
			sourceEntity.set("parentId", null);
			//window.$CurrentOperation = "DragTreeNode";
		}else{
			accept=false;
		}
		draggingInfo.set("accept", accept);
		if(accept){		
			updateActionKnowledge.execute();
		}else{
			dorado.MessageBox.alert("不接受的拖拽");
		}
	}catch(e){
		draggingInfo.set("accept", false);
		dorado.MessageBox.alert("不接受的拖拽");
	}
};

// @Bind #dataTreeKnowledge.onReady
!function(self, arg, dataTypeKnowledge, dataTypeStep,dataTypeAnswer) {
	dorado.DataPath
			.registerInterceptor(
					"currentKnowledge",
					function(data) {
						var entity = self.get("currentNode.data");
						return (entity && entity.dataType == dataTypeKnowledge) ? entity
								: null;
					}, function(dataType) {
						return dataTypeKnowledge;
					});
	dorado.DataPath.registerInterceptor("currentStep", function(data) {
		var entity = self.get("currentNode.data");
		return (entity && entity.dataType == dataTypeStep) ? entity : null;
	}, function(dataType) {
		return dataTypeStep;
	});
	dorado.DataPath.registerInterceptor("currentAnswer", function(data) {
		var entity = self.get("currentNode.data");
		return (entity && entity.dataType == dataTypeAnswer) ? entity : null;
	}, function(dataType) {
		return dataTypeAnswer;
	});
};

// @Bind #buttonSave.onClick
!function(self, arg) {
	window.saveAlldata();
};
// @Bind #buttonCancel.onClick
!function(self, arg) {
	var dataTreeKnowledge = view.id("dataTreeKnowledge");
	var entity = dataTreeKnowledge.get("currentEntity");
	if (entity) {
//		dorado.MessageBox.show({
//			title : "提示",
//			icon : dorado.MessageBox.INFO_ICON,
//			message : "确定要取消当前操作?",
//			buttons : [ "yes", "no" ],
//			detailCallback : function(buttonId) {
//				if (buttonId == "yes") {
					entity.cancel();
//				}
//			}
//		});
	}

};

// @Bind #dataTreeKnowledge.onCurrentChange
!function(self, arg) {
	var dataSetKnowledge = view.id("dataSetKnowledge");
	var currentknowledge = dataSetKnowledge.getData("!currentKnowledge");
	var currentStep = dataSetKnowledge.getData("!currentStep");
	var currentAnswer = dataSetKnowledge.getData("!currentAnswer");
	if (currentknowledge) {// 选中的是模块节点
		view.id("fieldSetKnowledge").set("visible", true);
		view.id("fieldSetStep").set("visible", false);
		view.id("fieldSetAnswer").set("visible", false);
		view.id("buttonAddSubKnowledge").set("disabled", false);
		view.id("buttonAddStepSub").set("disabled", false);
		view.id("buttonAddAnswerSub").set("disabled", true);		
	} else if (currentStep) {// 选中的是步骤节点
		view.id("fieldSetKnowledge").set("visible", false);
		view.id("fieldSetStep").set("visible", true);	
		view.id("fieldSetAnswer").set("visible", false);
		view.id("buttonAddSubKnowledge").set("disabled", true);
		view.id("buttonAddStepSub").set("disabled", false);
		view.id("buttonAddAnswerSub").set("disabled", false);	
	} else if (currentAnswer) {// 选中的是步骤节点
		view.id("fieldSetKnowledge").set("visible", false);
		view.id("fieldSetStep").set("visible", false);
		view.id("fieldSetAnswer").set("visible", true);
		view.id("buttonAddSubKnowledge").set("disabled", true);
		view.id("buttonAddStepSub").set("disabled", true);
		view.id("buttonAddAnswerSub").set("disabled", true);
	}
	
};
//@Bind #dataTreeKnowledge.onRenderNode
!function(arg) {
	var entity=arg.node.get("data");
	if (entity.isDirty()&&entity.state == dorado.Entity.STATE_NEW) {
		var img = ">dorado/res/images/new-node.gif";
		arg.dom.innerHTML = arg.node.get("label") + "&nbsp;<img src=\""
				+ $url(img) + "\">";
		arg.processDefault = false;
	} else {
		arg.processDefault = true;
	}
};
// @Bind #customDropDownSelectStep.onValueSelect
!function(self, arg,dataSetKnowledge) {
	var value = arg.selectedValue;
	var currentAnswer = dataSetKnowledge.getData("!currentAnswer");
	if(typeof value.name == "undefined"){
		currentAnswer.set("nextKey", null);
		currentAnswer.set("nextKeyName", "");
	}else{
		currentAnswer.set("nextKey", value.id);
		currentAnswer.set("nextKeyName", value.name);
	}
	arg.processDefault = false;
};

dorado sample center main manager代码

var dirtyEntityNum = 0;

function refreshActions() {
	var node = view.get("#treeExamples.currentNode");
	view.set({
		"^onCurrentNode.disabled" : node == null,
		"^onCurrentCategory.disabled" : (node == null || node
				.get("bindingConfig.name") != "Category"),
		"^onCurrentExample.disabled" : (node == null || node
				.get("bindingConfig.name") != "Example")
	});

	var disabled = true;
	if (node != null) {
		var entity = node.get("data");
		disabled = !entity.isDirty();
	}
	view.set({
		"^onDirtyNode.disabled" : disabled,
		"^onDirty.disabled" : dirtyEntityNum == 0
	});
}

// @Bind @CategoryNode.onInsert
// @Bind @ExampleNode.onInsert
// @Bind @ExampleSource.onInsert
!function(arg) {
	var entityList = arg.entityList;
	var maxSortFlag = 0;
	entityList.each(function(entity) {
		var sortFlag = entity.get("sortFlag");
		if (sortFlag <= maxSortFlag) {
			maxSortFlag++;
			entity.set("sortFlag", maxSortFlag);
		} else {
			maxSortFlag = sortFlag;
		}
	});
}

// @Bind @CategoryNode.onRemove
// @Bind @ExampleNode.onRemove
// @Bind @ExampleSource.onRemove
!function(arg) {
	arg.entity.set("sortFlag", 0);
}

// @Bind @CategoryNode.onStateChange
// @Bind @ExampleNode.onStateChange
// @Bind @ExampleSource.onStateChange
!function(arg) {
	if (arg.oldState == dorado.Entity.STATE_NONE) {
		dirtyEntityNum++;
	} else if (arg.newState == dorado.Entity.STATE_NONE) {
		dirtyEntityNum--;
	} else if (arg.oldState == dorado.Entity.STATE_NEW
			&& arg.newState == dorado.Entity.STATE_DELETED) {
		dirtyEntityNum--;
	}
	refreshActions();
}

// @Bind #actionAddCategory.onExecute
!function(dsCategories, treeExamples) {
	var parentCategory = dsCategories.getData("!CURRENT_CATEGORY");
	var data = {
		label : "<新分类>"
	};
	if (parentCategory) {
		parentCategory.createChild("categories", data);
	} else {
		dsCategories.getData().createChild(data);
	}

	var currentNode = treeExamples.get("currentNode");
	if (currentNode) {
		currentNode.expandAsync();
	}
}

// @Bind #actionAddExample.onExecute
!function(dsCategories, treeExamples) {
	var parentCategory = dsCategories.getData("!CURRENT_CATEGORY");
	var data = {
		label : "<新示例>"
	};
	if (parentCategory) {
		parentCategory.createChild("examples", data);

		var currentNode = treeExamples.get("currentNode");
		if (currentNode) {
			currentNode.expandAsync();
		}
	} else {
		var currentExample = dsCategories.getData("!CURRENT_EXAMPLE");
		if (currentExample) {
			currentExample.createBrother(data);
		}
	}
}

// @Bind #actionLinkExample.onExecute
!function(dialogSelectExample) {
	dialogSelectExample.show();
}

// @Bind #actionRemove.onExecute
!function(dsCategories) {
	var entity = dsCategories.getData("!CURRENT_NODE");
	if (entity) {
		entity.remove();
	}
}

// @Bind #actionCancel.onExecute
!function(dsCategories) {
	var entity = dsCategories.getData("!CURRENT_NODE");
	if (entity) {
		entity.cancel();
	}
}

// @Bind #actionSave.onSuccess
!function() {
	dirtyEntityNum = 0;
	refreshActions();
}

// @Bind #treeExamples.onReady
!function(self, CategoryNode, ExampleNode) {
	dorado.DataPath.registerInterceptor("CURRENT_CATEGORY", function(data) {
		var entity = self.get("currentNode.data");
		return (entity && entity.dataType == CategoryNode) ? entity : null;
	}, function(dataType) {
		return CategoryNode;
	});
	dorado.DataPath.registerInterceptor("CURRENT_EXAMPLE", function(data) {
		var entity = self.get("currentNode.data");
		return (entity && entity.dataType == ExampleNode) ? entity : null;
	}, function(dataType) {
		return ExampleNode;
	});
}

// @Bind #treeExamples.onCurrentChange
!function(self, cardbook) {
	refreshActions();
	var nodeType = self.get("currentNode.bindingConfig.name"), index = 0;
	if (nodeType) {
		index = (nodeType == "Category") ? 1 : 2;
	}
	cardbook.set("currentControl", index);
}

// @Bind #treeExamples.onRenderNode
!function(arg) {
	var entity = arg.node.get("data");
	if (entity.isDirty()) {
		var img = ">images/"
				+ ((entity.state == dorado.Entity.STATE_NEW) ? "new-node.gif"
						: "modified-node.gif");
		arg.dom.innerHTML = arg.node.get("label") + "&nbsp;<img src=\""
				+ $url(img) + "\">";
		arg.processDefault = false;
	} else {
		arg.processDefault = true;
	}
}

// @Bind #treeExamples.onDataNodeCreate
!function(self, arg) {
	var entity = arg.data;
	if (entity.state == dorado.Entity.STATE_NEW) {
		setTimeout(function() {
			self.set("currentNode", arg.node);
		}, 50);
	}
}

// @Bind #treeExamples.onContextMenu
!function(arg, menuTree) {
	menuTree.show({
		position : {
			left : arg.event.pageX,
			top : arg.event.pageY
		}
	});
}

// @Bind #treeExamples.onDraggingSourceMove
!function(arg) {
	var draggingInfo = arg.draggingInfo;
	var sourceNode = draggingInfo.get("object");
	var sourceType = sourceNode.get("bindingConfig.name");

	var targetNode = draggingInfo.get("targetObject");
	if (targetNode) {
		var accept;
		if (sourceType == "Category") {
			accept = (targetNode.get("bindingConfig.name") != "Example");
		} else {
			accept = (targetNode.get("bindingConfig.name") == "Category");
		}
		draggingInfo.set("accept", accept);
	}
}

// @Bind #buttonOk.onClick
!function(treeCategories, treeExamples, dialogSelectExample) {
	var category = treeCategories.get("currentNode.data");
	if (!category) {
		dorado.MessageBox.alert("请选择一个有效的分类。");
		return;
	}

	var currentCategoryNode = treeExamples.get("currentNode");
	if (currentCategoryNode.get("bindingConfig.name") == "Example")
		currentCategoryNode = currentCategoryNode.get("parent");
	if (category == currentCategoryNode.get("data")) {
		dorado.MessageBox.alert("请选择一个不同的分类。");
		return;
	}

	var example = treeExamples.get("currentNode.data");
	example = example.clone();
	example.set("sortFlag", 0);
	category.get("examples").insert(example);
	dialogSelectExample.hide();
}

// @Bind #buttonCancel.onClick
!function(dialogSelectExample) {
	dialogSelectExample.hide();
}

节点数据删除ajax提交后更新页面节点的例子

// @Bind #removeElement.onClick
!function(self, arg) {
	var currentnode = view.id("treeBusinessElement").get("currentNode");
	if (currentnode.get("bindingConfig.name") == "levelBusinessElement"
			&& currentnode.get("level") != 1) {
		var superiorId = currentnode.get("parent.data.id");
		var subordinateId = currentnode.get("data.id");
		var commandRemoveElement = view.id("commandRemoveElement");
		commandRemoveElement.set("parameter", {
			superiorId : superiorId,
			subordinateId : subordinateId
		});
		commandRemoveCommission.execute(function() {
			currentnode.get("data").remove();
		});
	} else {
		dorado.MessageBox.alert("请选择顶层节点");
	}
}