gpt4 book ai didi

search - JQuery Dynatree - 按名称搜索节点

转载 作者:行者123 更新时间:2023-12-04 10:04:55 27 4
gpt4 key购买 nike

我想开始在我的页面上使用 Dynatree,但是我可能需要按名称搜索我的树。你知道怎么做吗?

最佳答案

我不仅需要匹配节点,还需要这些节点的完整路径。我写了这个功能,它对我有用。

库的修改:

var clear = true;

DynaTreeNode.prototype.search = function(pattern){

if(pattern.length < 1 && !clear){
clear = true;
this.visit(function(node){
node.expand(true);
node.li.hidden = false;
node.expand(false);
});
} else if (pattern.length >= 1) {
clear = false;
this.visit(function(node){
node.expand(true);
node.li.hidden = false;
});

for (var i = 0; i < this.childList.length; i++){
var hide = {hide: false};
this.childList[i]._searchNode(pattern, hide);
}
}
},

DynaTreeNode.prototype._searchNode = function(pattern, hide){

if (this.childList){
// parent node

var hideNode = true;
for(var i = 0; i < this.childList.length; i++){
var hideChild = {hide: false};
this.childList[i]._searchNode(pattern, hideChild);
hideNode = hideNode && hideChild.hide;
}
if(hideNode && !this._isRightWithPattern(pattern)){
this._hideNode();
hide.hide = true;
} else {
hide.hide = false;
}

} else {
// leaf
if (!this._isRightWithPattern(pattern)){
this._hideNode();
hide.hide = true;
} else {
hide.hide = false;
}
}
},

DynaTreeNode.prototype._isRightWithPattern = function(pattern){
if((this.data.title.toLowerCase()).indexOf(pattern.toLowerCase()) >= 0){
return true;
}
return false;
},

DynaTreeNode.prototype._hideNode = function(){
if(this.li) {
this.li.hidden = true;
}
}

用:
$("tree").dynatree("getRoot").search(pattern);

关于search - JQuery Dynatree - 按名称搜索节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12277797/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com