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

前端 未结 14 2421
北恋
北恋 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:00

    Unable to get harpo's solution to work, and unwilling to use Olivier's solution as it uses internal jsTree functions, I came up with a different approach.

    $('#tree').jstree('get_selected').attr('id')
    

    It's that simple. The get_selected function returns an array of selected list items. If you do .attr on that array, jQuery will look at the first item in the list. If you need IDs of multiple selections, then treat it as an array instead.

提交回复
热议问题