现在我的XTREE有checkbox,也可以正常显示树,就差checkbox的父节点选中,子节点也选中,还有如子节点全部取消,父节点也取消的问题,想试着自己封装,无奈JS是在太烂了,请各位帮忙看看啊,一下是我的XTREE.JS:

解决方案 »

  1.   

    用class id进行标记。 然后通过 你点击的父节点 获取参数,然后用jquery 把这个参数相关的子节点递归选择就行了。 代码会有点复杂。。
      

  2.   

    LS的,是想用JS,扩展XTREE.JS,让他有我说的功能,文件太大,怎么上传啊
      

  3.   

    WebFXTreeItem.prototype.toString = function (nItem, nItemCount) {
    var foo = this.parentNode;
    var indent = '';
    if (nItem + 1 == nItemCount) { this.parentNode._last = true; }
    var i = 0;
    while (foo.parentNode) {
    foo = foo.parentNode;
    indent = "<img id=\"" + this.id + "-indent-" + i + "\" src=\"" + ((foo._last)?webFXTreeConfig.blankIcon:webFXTreeConfig.iIcon) + "\">" + indent;
    i++;
    }
    this._level = i;
    if (this.childNodes.length) { this.folder = 1; }
    else { this.open = false; }
    if ((this.folder) || (webFXTreeHandler.behavior != 'classic')) {
    if (!this.icon) { this.icon = webFXTreeConfig.folderIcon; }
    if (!this.openIcon) { this.openIcon = webFXTreeConfig.openFolderIcon; }
    }
    else if (!this.icon) { this.icon = webFXTreeConfig.fileIcon; }
    var label = this.text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
    var str = "<div id=\"" + this.id + "\" ondblclick=\"webFXTreeHandler.toggle(this);\" class=\"webfx-tree-item\" onkeydown=\"return webFXTreeHandler.keydown(this, event)\">" +
    indent +
    "<img id=\"" + this.id + "-plus\" src=\"" + ((this.folder)?((this.open)?((this.parentNode._last)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.tMinusIcon):((this.parentNode._last)?webFXTreeConfig.lPlusIcon:webFXTreeConfig.tPlusIcon)):((this.parentNode._last)?webFXTreeConfig.lIcon:webFXTreeConfig.tIcon)) + "\" onclick=\"webFXTreeHandler.focusI(this);webFXTreeHandler.blurI(this);"+this.action+"\">" +

    "<input type='checkbox' name='checkGroupId"+this.kind+"' class='webfx-tree-checkbox' id='"+this.kind+this.targetId+"' value='"+this.targetId+"' />"+

    "<img id=\"" + this.id + "-icon\" class=\"webfx-tree-icon\" src=\"" + ((webFXTreeHandler.behavior == 'classic' && this.open)?this.openIcon:this.icon) + "\" onclick=\"webFXTreeHandler.select(this);\">" +
    "<a href=\"" + this.action + "\" id=\"" + this.id + "-anchor\" onfocus=\"webFXTreeHandler.focus(this);\" onblur=\"webFXTreeHandler.blur(this);\"" +
    (this.target ? " target=\"" + this.target + "\"" : "") +
    ">" + label + "</a></div>" +
    "<div id=\"" + this.id + "-cont\" class=\"webfx-tree-container\" style=\"display: " + ((this.open)?'block':'none') + ";\">";
    var sb = [];
    for (var i = 0; i < this.childNodes.length; i++) {
    sb[i] = this.childNodes[i].toString(i,this.childNodes.length);
    }
    this.plusIcon = ((this.parentNode._last)?webFXTreeConfig.lPlusIcon:webFXTreeConfig.tPlusIcon);
    this.minusIcon = ((this.parentNode._last)?webFXTreeConfig.lMinusIcon:webFXTreeConfig.tMinusIcon);
    return str + sb.join("") + "</div>";
    }这个是TOSTRING方法,其中的CHECKBOX就是我要的,但是里面没有Oncilck事件
      

  4.   

    就红色部分啊,其他不用看的啊,然后写个Onclick事件就好了啊