使用ui插件时Jstree节点不起作用
我发现使用 ui 插件会破坏树节点的链接。这不是什么新鲜事,我在其他地方找到了对此问题的参考。第一个原因是 jquery 验证插件 v1.6 的问题。我没有使用该插件,所以这不是原因。
我还发现了一篇很好的帖子,描述了将 jstree-clicked 类添加到 标记的几种方法。这看起来很有希望,但当我尝试时,我没有注意到任何区别。这是一个非常简单的示例:
<div id="treediv">
<ul>
<li id="page1"><a href="http://www.yahoo.com" class="jstree-clicked">YAHOO!</a></li>
</ul>
</div>
<script type="text/javascript" class="source">
$(function () {
$("#treediv")
.jstree({
"core" : {
"animation" : 0
},
"themes" : {
"theme" : "classic"
},
"plugins" : [ "themes", "html_data", "cookies", "ui" ]
});
});
</script>
如果我取出 ui 插件,则单击链接将按预期转到 yahoo.com。有人有什么想法吗?
I've found that using the ui plugin breaks the links for the tree nodes. This isn't anything new, I've found references to this problem elsewhere. The first cause was a problem with v1.6 of the jquery validation plugin. I'm not using that plugin, so that can't be the cause.
I also found a good posting describing a few ways of adding the jstree-clicked class to the <a>
tag. That looked promising, but when I tried it I didn't notice any difference. Here is a very simple example:
<div id="treediv">
<ul>
<li id="page1"><a href="http://www.yahoo.com" class="jstree-clicked">YAHOO!</a></li>
</ul>
</div>
<script type="text/javascript" class="source">
$(function () {
$("#treediv")
.jstree({
"core" : {
"animation" : 0
},
"themes" : {
"theme" : "classic"
},
"plugins" : [ "themes", "html_data", "cookies", "ui" ]
});
});
</script>
If I take out the ui plugin, then clicking the link takes me to yahoo.com as expected. Does anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我在 jstree 讨论组中找到了答案。我相信 ui 插件允许“选择”节点,但单击不会传递到锚标记。因此,我必须绑定一个在选择节点时要执行的函数。我使用如下所示的 .bind 完成了此操作:
作为附带好处,此示例还向我展示了单击树节点并在另一个 div 中显示动态内容是多么容易。例如,假设树节点定义如下(使用 html_data jstree 插件和 struts2):
单击该树节点将导致执行 do-something 操作,结果将显示在 id 为“contents”的 div 中”。
I think I found the answer on the jstree discussion group. I believe that the ui plugin allows the nodes to be "selected", but the click doesn't pass through to the anchor tag. So, I have to bind a function to be executed whenever a node is selected. I accomplished this with a .bind like the following:
As a side benefit, this example also showed me how easy it is to click on a tree node and show dynamic contents in another div. For example, suppose the tree node was defined as follows (using html_data jstree plugin and struts2):
Clicking on that tree node will cause the do-something action to be executed, and the results will be displayed in the div with the id "contents".