Hello,

I'm french, sorry for my English, thank you google translation! ;)

I'd like to make ajax calls to load sub-nodes in my treeview.
I have the following tree:

Tree HTML :

<ul id="tree">
  <li id="1"><span>Item 1</span></li>
  <li id="2"><span id="item-2">Item 2</span></li>
  <li id="3"><span>Item 3</span></li>
</ul>

Method JS :

$("span[id]").click(function() {
  var toto = $(this).parent();
  if (toto.find(">ul").length == 0) {
    var id = $(this).attr("id").substring("item-".length);
    $.post("/Export/GetChildItem", { "id": id }, function(data) {
      var branches = $(data).appendTo("#" + id);
      $("#tree").treeview({
        add: branches
      });
    });
  }

});

Result :

<ul id="tree">
  <li id="1"><span>Item 1</span></li>
  <li id="2"><span id="item-2">Item 2</span>
    <ul>
      <li><span id="item-2-1">Item 2-1</span></li>
      <li><span>Item 2-2</span></li>
    </ul>
  </li>
  <li id="3"><span>Item 3</span></li>
</ul>

When I click on "item 2", no problem. If I click on "item 2-1", no
event, why?
I've tried everything, I do not see...

Thanks

Reply via email to