dojo tree edit的使用[前端]
var store = new mydata.JsonRestStore({ target: "<%=ResolveUrl("~/uieditserver.ashx")%>" });
typestore = new mydata.JsonRestStore({
target: "<%=ResolveUrl("~/uieditserver.ashx") %>",
labelAttribute: "pagename"
});
treeModel = new dijit.tree.ForestStoreModel({
store: typestore,
deferItemLoadingUntilExpand: true,
rootLabel: "系统功能树",
query: { operation: 'pageList.FindTree' },
childrenAttrs: ["Details"]
});
var treeControl = new dijit.Tree({
id: "atreepowers",
model: treeModel,
autoExpand: true,
showRoot: true,
_createTreeNode: function (args) {
var tnode = new dijit.Tree._TreeNode(args);
tnode.labelNode.innerHTML = args.label;
if (args.item.root) {//如果是根
return tnode;
}
var cb = new dijit.form.CheckBox();
cb.placeAt(tnode.labelNode, "first");
dojo.connect(cb, "onChange", function () {
var treeNode = dijit.getEnclosingWidget(this.domNode.parentNode);
dojo.publish("/checkbox/clicked", [{
"checkbox": this,
"item": treeNode.item
}]);
});
return tnode;
}
});
dojo.subscribe("/checkbox/clicked", function (message) {
message.item.ischecked = message.checkbox.checked;
setpersiblings(message.checkbox.getParent());
});
function setpersiblings(selectNode) {
if (!selectNode) return;
//先子级,孙级
var checked = selectNode.item.ischecked;
var childrens = selectNode.getChildren();
for (var i = 0; i < childrens.length; i++) {
childrens[i].item.ischecked = checked;
dijit.getEnclosingWidget(childrens[i].labelNode.firstElementChild)
.set('checked', checked);
}
var iparentknow = 0;
//位置,往前获取数据,往后获取数据,同级
var getparentchildrens = selectNode.getParent();//.getChildren();
while (getparentchildrens && getparentchildrens.isTreeNode && !getparentchildrens.item.root) {
var getchildrens = getparentchildrens.getChildren();
for (var i = 0; i < getchildrens.length; i++) {
if (getchildrens[i].item.ischecked) {
iparentknow += 1;
}
}
if (iparentknow === getchildrens.length) {
getparentchildrens.item.ischecked = true;
dijit.getEnclosingWidget(getparentchildrens.labelNode.firstElementChild)
.set('checked', true);
}
else {
getparentchildrens.item.ischecked = false;
dijit.getEnclosingWidget(getparentchildrens.labelNode.firstElementChild)
.set('checked', false);
}
getparentchildrens = getparentchildrens.getParent();//.getChildren();
}
}