问题描述
我正在使用jstree,如果可能,我想知道如何隐藏/显示节点。我给列表项目一个猫ID来选择他们与jQuery,但这是行不通的。
I'm working with jstree and I would like to know how to hide/show nodes if possible. I gave the list items a "cat" id to select them with jquery but this doesn't work.
以下是代码。
html:
<div class="resultsContent">
<div class="demo" id="demo_1">
<ul>
{% for ipc in ipcs %}
{% ifequal ipc.back_list 1 %}
</ul></li>
{% endifequal %}
{% ifequal ipc.kind "c" %}
<li id="{{ ipc.symbol }} cat" rel="node-type">
{% else %}
<li id="{{ ipc.symbol }} cat" rel="node-type">
{% endifequal %}
{% endfor %}
</ul>
</div>
</div>
script:
script:
jQuery('#demo_1')
.jstree({
plugins : [ "themes", "html_data", "checkbox" ],
themes : { theme: "default", dots : false, icons : false },
core : { "initially_open" : [ "{{ top_symbol }}" ] },
})
$("#cat").slice(5, 10).hide(); //Hide some nodes
推荐答案
您将生成一个ID元素,其ID由IPC符号值加上黑色空格,加上单词cat。
It seems at your code that you are generating li elements with an ID composed by a IPC Symbol value plus a black space, plus the word "cat".
<li id="{{ ipc.symbol }} cat" rel="node-type">
但是,您的选择器试图获取ID为cat的元素
But, your selector is trying to get an element whose ID is exactly "cat"
$("#cat").slice(5, 10).hide(); //Hide some nodes
也许你可以使用不同的jQuery选择器。例如,:
Maybe you could use a different jQuery selector. By the example, Attribute Contains Selector:
$("li[id*='cat']").slice(5, 10).hide(); //Hide nodes with the string 'cat'
或者,在这种情况下更合适(因为您正在查找整个单词):
Or the Attribute Contains Word Selector, more appropriate in this case (because you are looking for a whole word):
$("li[id~='cat']").slice(5, 10).hide(); //Hide nodes containing the word 'cat'
这篇关于jsTree显示/隐藏节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!