gpt4 book ai didi

jquery - 隐藏 JSTree 中的特定节点

转载 作者:行者123 更新时间:2023-12-01 04:08:01 25 4
gpt4 key购买 nike

我有一个标准的 jstree,其中包含文件夹对象列表。用户能够对文件夹名称进行基本搜索,并且我想隐藏与搜索不匹配的所有文件夹。一切工作正常,直到我需要实际隐藏不匹配的节点的部分。

//Iterate through all elements of the tree.
var xmlString = $("#standardTree").jstree("get_xml");
var xmlDOM = $.parseXML(xmlString);
var items = $(xmlDOM).find("root item");

$.each(items, function (key, item) {
//If a node's text doesn't match the search, hide that node.
if ($(item).text() != result.searchString) {

//**Not sure what to do here, this doesn't work.**
$(item).hide();
}
});

最佳答案

这对我有用

var isFiltered  = false;
function filter() {
isFiltered = !isFiltered;
var filterText = document.getElementById("newParent").value;
var $tree = $('#jstree');
$($tree.jstree().get_json($tree, {
flat: true
}))
.each(function(index, value) {
var node = $("#jstree").jstree().get_node(this.id);
if (isFiltered && !node.text.includes(filterText))
$("#jstree").jstree(true).hide_node(node);
else
$("#jstree").jstree(true).show_node(node);

});
}

关于jquery - 隐藏 JSTree 中的特定节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24865424/

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