How do I get the id of the selected node in jsTree?

前端 未结 14 2396
北恋
北恋 2020-12-29 22:38

How can I get the id of the selected node in a jsTree?

function createNewNode() {
  alert(\'test\');
  var tree = $.tree.reference(\"#basic_html\");
  select         


        
14条回答
  •  甜味超标
    2020-12-29 23:22

    Nodes in jsTree are essentially wrapped list items. This will get you a reference to the first one.

    var n = $.tree.focused().get_node('li:eq(0)')
    

    You can replace $.tree.focused() if you have a reference to the tree.

    To get the id, take the first matched element

    if (n.length)
        id = n[0].id
    

    or you can use the jQuery attr function, which works on the first element in the set

    id = n.attr('id');
    

提交回复
热议问题