Jstree nodes don't work when ui plugin is used

前端 未结 1 814
死守一世寂寞
死守一世寂寞 2020-12-20 17:58

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

相关标签:
1条回答
  • 2020-12-20 18:23

    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;
      }) 
    

    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>
    

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

    0 讨论(0)
提交回复
热议问题