我想開始在我的頁面上使用Dynatree,但是我可能需要按名稱搜索我的樹。你知道如何做到這一點?JQuery Dynatree - 按名稱搜索節點
6
A
回答
1
目前還沒有搜索功能,但你可以使用這樣的事情(未測試)
var match = null;
tree.visit(function(node){
if(node.data.title === "foo"){
match = node;
return false; // stop traversal (if we are only interested in first match)
}
});
alert("Found " + match);
15
我需要有不僅匹配的節點,也是整個路徑到這些節點。我寫了這個功能,它適用於我。
修改爲庫:
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);
0
我已經做到了這樣
<style>
span.occurance a.dynatree-title{background-color:#3AFF22;}
</style>
DynaTreeNode.prototype.find = function (needle) {
needle = (needle || '');
if (needle.length >= 1) {
var occurs = [];
this.visit(function (node) {
$(node.span).removeClass('occurance'); //remove pervious findings
if (node.data.title.indexOf(needle) != -1) {
occurs.push(node);
node._expandPath();
}
});
for (indx in occurs) { // mark findings
$(occurs[indx].span).addClass('occurance');
}
} else {
$('span.dynatree-node.occurance').removeClass('occurance');
}
},
DynaTreeNode.prototype._expandPath = function() {
var path = [],
node = this;
while (node = node.getParent()) {
path.push(node);
}
for (indx in path) {
path[indx].expand(true)
}
}
用法:
[your selector].dynatree("getRoot").find('needle');
0
感謝@ mar10我犯了一個小的,簡單的功能來搜索與標題節點:http://www.designchemical.com/blog/index.php/jquery/live-text-
// If searchFrom is null, root is used
function seachFolderNodeWithName(name, searchFrom) {
if (name == null) {
return undefined;
}
if (searchFrom == null) {
searchFrom = jQuery('#tree').dynatree("getRoot");
}
var match = undefined;
searchFrom.visit(function (node) {
if (node.data.title === name) {
match = node;
return false; // Break if found
}
});
return match;
};
相關問題
- 1. XSL:搜索節點名稱
- 2. JQuery Dynatree - 如何使用級別分隔符搜索節點?
- 3. FQL按名稱搜索地點
- 4. 如何按名稱搜索要點
- 5. Trip Advisor API按地點搜索名稱
- 6. Solr搜索:按字母搜索名稱
- 7. 按名稱搜索類
- 8. 按分類名稱搜索
- 9. 檢索XML節點名稱
- 10. 按名稱提取節點
- 11. 如何搜索具有相同節點名稱但不同父節點名稱的嵌套節點?
- 12. jQuery Dynatree插件 - 如何禁用節點?
- 13. jQuery DynaTree - 如何動態創建節點
- 14. DynaTree動態展開節點
- 15. jQuery Dynatree,按標題選擇一個子節點?
- 16. 按關鍵字搜索按類別搜索按名稱搜索關鍵字
- 17. 搜索節點
- 18. jsTree:按名稱展開節點
- 19. 如何獲取節點和源節點jQuery dynatree?
- 20. 搜索名稱
- 21. dynatree中的展開節點
- 22. 搜索在JCR節點名稱子用CQ的QueryBuilder
- 23. 搜索XML其中節點名稱存在sql
- 24. 如何根據名稱搜索某個節點?
- 25. 搜索具有特定名稱標籤的節點
- 26. 按關鍵字搜索節點
- 27. 按節點內容搜索nokgiri :: XML
- 28. SQL Server按名稱搜索列
- 29. 在awk中按名稱搜索列
- 30. 名稱爲內搜索欄按鈕
請參閱本Dynatree是一個簡單的UL> LI – Rahul