There any possibility to add data dropping a dom element into the tree

173 Views Asked by At

I want to enable the drag and drop to add child node but the child node is not into the tree. So I'm thinking in use draggable jquery ui function to drag a element into a jqtree node but I don't know how to capture the node dropped. Any ideas?

EDIT (More info)

I've tried this.

$('#tree1').tree({
  data: data,
  dragAndDrop: true,
  onCreateLi: function (node, $li) {
    $li.droppable({
      drop: function (event, ui) {
        alert($(this).attr("id"));
      }
    });
  }
});

but the this element does not contain information about node.

1

There are 1 best solutions below

0
On BEST ANSWER

I'm going to answser myself. Based on this example I attached a droppable object to a tree element and when a object is dropped I access to a custom property.

$('#tree1').tree({
  data: data,
  dragAndDrop: true,
  onCreateLi: function (node, $li) {
    $li.find(".jqtree-element").prop("id",node.id);
    $li.find(".jqtree-element").droppable({
      hoverClass: "ui-state-active",
      drop: function (event, ui) {
        var id = $(this).prop("id");
          alert(id);
          }
        });
      }
  });