xtree的节点id生成机制有问题(在一个页面生成多个tree的情况下,单个的时候没太注意)。用ajax刷新重建树的时候出现了所有节点id的值都一样的状况。引起的效果是节点不能收缩了。就这原因找了有大几个小时的时间。好在找到问题的关键。于是修改了xtree节点的构造方法。由自己指定id。修改的地方如下
/*
* WebFXTreeAbstractNode class
*/
function WebFXTreeAbstractNode(sId, sText, sAction) {
this.childNodes = [];
this.id = sId; //这里进行了更改
this.text = sText || webFXTreeConfig.defaultText;
this.action = sAction || webFXTreeConfig.defaultAction;
this._last = false;
webFXTreeHandler.all[this.id] = this;
}
/*
* WebFXTree class
*/
function WebFXTree(sId, sText, sAction, sBehavior, sIcon, sOpenIcon) {
this.base = WebFXTreeAbstractNode;
this.base(sId, sText, sAction); //这里进行了更改
this.icon = sIcon || webFXTreeConfig.rootIcon;
this.openIcon = sOpenIcon || webFXTreeConfig.openRootIcon;
/* Defaults to open */
if (webFXTreeConfig.usePersistence) {
this.open = (webFXTreeHandler.cookies.getCookie(this.id.substr(18,this.id.length - 18)) == '0')?false:true;
} else { this.open = true; }
this.folder = true;
this.rendered = false;
this.onSelect = null;
if (!webFXTreeHandler.behavior) { webFXTreeHandler.behavior = sBehavior || webFXTreeConfig.defaultBehavior; }
}
/*
* WebFXTreeItem class
*/
function WebFXTreeItem(sId, sText, sAction, eParent, sIcon, sOpenIcon) {
this.base = WebFXTreeAbstractNode;
this.base(sId, sText, sAction); //这里进行了更改
/* Defaults to close */
if (webFXTreeConfig.usePersistence) {
this.open = (webFXTreeHandler.cookies.getCookie(this.id.substr(18,this.id.length - 18)) == '1')?true:false;
} else { this.open = false; }
if (sIcon) { this.icon = sIcon; }
if (sOpenIcon) { this.openIcon = sOpenIcon; }
if (eParent) { eParent.add(this); }
}
本文解决了xtree在页面生成多个树时出现的所有节点ID值相同的问题,导致节点无法正常展开或折叠。通过修改节点构造方法来自定义ID,确保每个节点ID的唯一性。
195

被折叠的 条评论
为什么被折叠?



