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();
}
}

随机推荐

  1. 【题解】【BST】【Leetcode】Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路: ...

  2. Sharing

    To store English words, one method is to use linked lists and store a word letter by letter. To save ...

  3. scanf从文件中读入,printf写入到文件

    重定向方式读写文件 #include <stdio.h> #define LOCAL int main() { #ifdef LOCAL freopen("input.txt&q ...

  4. windows下npm scripts不能执行的问题

    最近在学webpack为了方便把运行脚本写入package.json文件中,如下: "scripts": { "start": "webpack-de ...

  5. Generator函数语法解析

    转载请注明出处: Generator函数语法解析 Generator函数是ES6提供的一种异步编程解决方案,语法与传统函数完全不同.以下会介绍一下Generator函数. 写下这篇文章的目的其实很简单 ...

  6. 04_Javascript初步第二天(下)

    错误对象 try{ aa();//这是一个未被定义的方法 }catch(e){ alert(e.name+":"+e.message);//输出:ReferenceError:aa ...

  7. 用Flask+Redis维护代理池

    GitHub:https://github.com/LXL-YAN/ProxyPool 视频讲解:https://www.bilibili.com/video/av19057145/?p=17

  8. Linux学习笔记之八————vim编辑器常用命令总结

    <1>从命令行模式到插入模式 i  :在光标前插入 a :在光标后插入 I  :在光标所处在的行的行首 A :在光标所处在的行的末尾 o  :在光标所处在的行的下一行 行首 O :在光标所 ...

  9. 通过github搭建个人博客

    今天突发奇想,想用GitHub搭建一个个人博客,就大概学习了一下,特此记录. 其实非常简单,首先要知道,这里是通过GitHub Pages进行搭建的,什么?不知道什么是GitHub Pages?Git ...

  10. virtualbox虚拟机与物理机windows文件共享

    必须安装virtualbox的增强功能包(VBoxGuestAdditions) 1.打开Linux系统,选择 设备->安装增强增强功能 2.等待其自动安装,当出现press return to ...