本文介绍了使用ui插件时,Jstree节点不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现使用ui插件会破坏树节点的链接。这不是什么新鲜事,我在其他地方找到了这个问题的参考。第一个原因是jquery验证插件的v1.6出现问题。我没有使用那个插件,所以这不是原因。

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.

我还发现了一个很好的帖子,描述了添加jstree点击类的几种方法< a> 标记。这看起来很有希望,但是当我尝试它时,我没有注意到任何差异。这是一个非常简单的例子:

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>

如果我拿出ui插件,然后点击链接就会按照预期将我带到yahoo.com。有没有人有任何想法?

If I take out the ui plugin, then clicking the link takes me to yahoo.com as expected. Does anyone have any ideas?

推荐答案

我想我。我相信ui插件允许选择节点,但点击不会传递到锚标签。所以,每当选择一个节点时,我必须绑定一个要执行的函数。我用.bind完成了这个,如下所示:

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:

  .bind("select_node.jstree", function (e, data) {
    var href = data.rslt.obj.children("a").attr("href");
    // this will load content into a div:
    $("#contents").load(href);
    // this will follow the link:
    document.location.href = href;
  })

作为附带好处,这个例子还向我展示了点击树节点并在另一个div中显示动态内容是多么容易。例如,假设树节点定义如下(使用html_data jstree插件和struts2):

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):

<li id="node1">
    <a href="do-something.action">Do Something</a>
</li>

单击该树节点将导致执行do-something操作,结果将是显示在id为contents的div中。

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".

这篇关于使用ui插件时,Jstree节点不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:19