WEB开发网
开发学院网页设计JavaScript DTree中致命的递归 阅读

DTree中致命的递归

 2010-09-14 13:43:23 来源:WEB开发网   
核心提示: 2. DTree中没有用于获取被选择节点的text值的方法,而其中的test方法完全可以被用来改造,DTree中致命的递归(2),// Get all selected nodes text (e.g. a,b,c,d,e) dTree.prototype.getText =functi

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

上一页  1 2 3 4 5  下一页

Tags:DTree 致命 递归

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接