简体   繁体   中英

load call only works on first node, not on leaves?

i thought i had solved my problem, but not. I use a normal call to load content and it works easy, fast and fine.

    $( document ).ready(function() {
        $('#leftmenu').jstree();
        $('.jstreelink').click(function(){
            alert("Clicked!");
          $('#maincontent').load(this.href)
          return false;
        });
    });

    <div id="leftmenu">
       <ul>
           <li>Admin
               <ul>
                  <li><a class="jstreelink" href="backend/test4.php">task1</a></li>
                  <li><a class="jstreelink" href="backend/test3.php">task2</a></li>
               </ul>
           </li>

           <li>Moderator
               <ul>
                   <li><a class="jstreelink" href="backend/testp.php">task3</a></li>
                   <li><a class="jstreelink" href="backend/test1.php">task4</a></li>
               </ul>
           </li>

           <li><a class="jstreelink" href="backend/test.php">task5</a></li>

       </ul>
       </div>

I added a test alert, and i only get that alert when clicking on task5. I have tried different combinations, but when clicking on a leaf , nothing happens. Also checked with Firebug. repeatingly clicking on task 5 fires everytime the alert and does load the html in the maincontent div.

So it seems this isn't a normal jquery problem,but a problem with jsTree (and myself of course:))

I am using

jQuery v2.1.3 jsTree - v3.0.9

Thanks in advance for any comment.

Try this

$('#leftmenu').on("select_node.jstree", function(a,b){
    alert(b.node.a_attr.href);
    $('#maincontent').load(b.node.a_attr.href)
      return false;
});

Thanks maddin, but i already found the solution:

$( document ).ready(function() {
    $('#jstree').jstree();
    $('#jstree').on('click', '.jstreelink', function() {
     $('#maincontent').load(this.href);
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM