如何使用 jsTree 构造 HTML 数据以显示为树
我是 jsTree 的新手,我想从 HTML 页面内的
列表开始创建一棵树。这使用
html_data
插件(我希望这是正确的方式)。
和
我想知道:用 HTML 编写将由 jsTree 转换为树的数据的正确方法是什么?
jsTree 文档 建议这样做:
<li>
<a href="some_value_here">Node title</a>
<!-- UL node only needed for children - omit if there are no children -->
<ul>
<!-- Children LI nodes here -->
</ul>
</li>
但它没有指定将 id< 放在哪里/code> jsTree 用于引用数据的属性。
而且它似乎效果不太好。我见过有人将该代码嵌入
和
标签。例如:<div id="categories">
<ul>
<li><a href="#">Category 1</a>
<ul>
<li><a href="#">SubCategory 1</a></li>
<li><a href="#">SubCategory 2</a></li>
</ul>
</li>
<li><a href="#">Category 2</a></li>
</ul>
</div>
注意div标签中的id
。 这是正确的方法吗? 对我来说,仅使用 标签来编写节点的文本似乎不太舒服......如果我使用
< /code> 我失去了项目图标...
希望有人比我有更清晰的头脑。
I'm new with jsTree and I would like to create a tree starting from a <ul>
and <li>
list inside my HTML page. This using html_data
plugin (I hope it's the right way).
I'm wondering: which is the correct way to write in HTML the data that will be turned into a tree by jsTree?
jsTree documentation suggests this one:
<li>
<a href="some_value_here">Node title</a>
<!-- UL node only needed for children - omit if there are no children -->
<ul>
<!-- Children LI nodes here -->
</ul>
</li>
But it doesn't specify where to put the id
attribute that jsTree uses to refer to the data.
Moreover it doesn't seem to work so well. I've seen someone who embeds that code with a <div>
and a <ul>
tags. For instance:
<div id="categories">
<ul>
<li><a href="#">Category 1</a>
<ul>
<li><a href="#">SubCategory 1</a></li>
<li><a href="#">SubCategory 2</a></li>
</ul>
</li>
<li><a href="#">Category 2</a></li>
</ul>
</div>
Note that the id
in the div tag.
Is this a correct way?
For me it seems not so comfortable using <a href="#">
tags only to write the text of a node... And if I use a <span>
I loose the item icon...
Hope someone has a clearer head than mine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是 jsTree 用来绘制树的模式:
即每个节点都具有 jsTree 文档推荐的结构:
并且所有结构都必须用以下内容包装(文档没有说):
This seems to be the pattern used by jsTree to draw the tree:
That is each node has the structure recommended by jsTree documentation:
And all the structure must be wrapped with (what documentation doesn't say):