jsTree 显示/隐藏节点
我正在使用 jstree,我想知道如何隐藏/显示节点(如果可能)。我给列表项一个“cat”id 来使用 jquery 选择它们,但这不起作用。
这是代码。
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>
脚本:
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
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.
Here's the code.
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:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的代码中,您似乎正在生成 li 元素,其 ID 由 IPC 符号值加上一个黑色空格,加上单词“cat”组成。
但是,您的选择器正在尝试获取 ID 恰好为“cat”的元素,
也许您可以使用不同的 jQuery 选择器。例如,属性包含选择器:
或者 属性包含单词选择器,在这种情况下更合适(因为您正在寻找整个单词):
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".
But, your selector is trying to get an element whose ID is exactly "cat"
Maybe you could use a different jQuery selector. By the example, Attribute Contains Selector:
Or the Attribute Contains Word Selector, more appropriate in this case (because you are looking for a whole word):