DTree中致命的递归
2010-09-14 13:43:23 来源:WEB开发网2. DTree中没有用于获取被选择节点的text值的方法,而其中的test方法完全可以被用来改造。
// Get all selected nodes text (e.g. a,b,c,d,e)
dTree.prototype.getText = function () {
var value = new Array();
for (var n = 0; n < this.aNodes.length; n++) {
if (this.aNodes[n].check === "true" || this.aNodes[n].check === true) {
value[value.length] = this.aNodes[n].name;
}
}
return value;
};
3. DTree中没有考虑节点的CheckBox的disabled状态,由于节点中本来就包含CheckBox控件,所以可以直接使用它的disabled属性来进行控制。
var treeMode = "General"; //General or Special
// Event of the node check
dTree.prototype.checkNode = function(nodeId) {
var check = document.getElementById(("c" + this.obj) + nodeId);
var node = this.getNode(nodeId);
node.check = check.checked;
if (check.checked) {
if (treeMode == "Special") {
this.enableChildreNode(node, true);
}
else {
this.checkChildreNode(node, true);
}
//this.checkParentNode(node, true);
} else {
if (treeMode == "Special") {
this.enableChildreNode(node, false);
}
else {
this.checkChildreNode(node, false);
}
}
};
// Check all child nodes of the current node (recursive)
dTree.prototype.checkChildreNode = function (node, check) {
for (var i = 0; i < node.cNode.length; i++) {
var pCheck = document.getElementById(("c" + this.obj) + node.cNode[i].id);
if (pCheck && !pCheck.disabled) {
pCheck.checked = check;
node.cNode[i].check = check;
}
if (node.cNode[i].cNode.length > 0) {
this.checkChildreNode(node.cNode[i], check);
}
}
};
dTree.prototype.enableChildreNode = function(node, check) {
for (var i = 0; i < node.cNode.length; i++) {
var pCheck = document.getElementById(("c" + this.obj) + node.cNode[i].id);
if (pCheck) {
pCheck.disabled = check;
node.cNode[i].check = pCheck.checked = (check && !pCheck.disabled);
}
if (node.cNode[i].cNode.length > 0) {
this.enableChildreNode(node.cNode[i], check);
}
}
}
更多精彩
赞助商链接