2012-10-01 4 views
0

Я создал jsTree, как показано ниже.Как получить название выбранного узла в jsTree?

Теперь я хочу получить название выбранного узла. Я попробовал следующее, но он дал мне результат как «заголовок родительского узла + заголовок дочернего узла». Пожалуйста помоги.

bind("select_node.jstree", function(e, data){ 
    var selectedObj = data.rslt.obj; 
    selectedObj.text() 
}); 
+0

Я получил решение для этого. – Lalit

+0

Вы можете опубликовать решение, чтобы все могли извлечь из него выгоду. – Radek

+2

уверенный Radek !!! Возвращает название только выбранного узла. $ ('. Jstree-clicked'). Text(); – Lalit

ответ

0
var divselected = $('#treeViewDiv').jstree('get_selected'); 
1
<script type="text/javascript" > 
    $(function() { 
     $("#demo1") 
      .jstree({ 
       // the `plugins` array allows you to configure the active plugins on this instance 
       "plugins": ["themes", "html_data", "ui", "crrm", "hotkeys", "json_data"], 
       "core": { 
        "initially_open": ["phtml_1"] 
       } 
      }) 


      // EVENTS 
      // each instance triggers its own events - to process those listen on the container 
      // all events are in the `.jstree` namespace 
      // so listen for `function_name`.`jstree` - you can function names from the docs 
      .bind("loaded.jstree", function (event, data) { 
       // Every Work You like do in loaded jstree ... 
      }) 

     .bind("select_node.jstree", function (event, data) { 
      //`data.rslt.obj` is the jquery extended node that was clicked 
      alert("Selected node text :" + data.inst.get_text(data.rslt.obj)); 
      alert("Selected node Tag a text:" + data.rslt.obj.find('a').first().text()); 
      alert("Selected node Tag a title:" + data.rslt.obj.find('a').attr("title")); 
      alert("Selected node Tag a href Address" + data.rslt.obj.children("a").attr("href")); 
      alert("Selected node Parent ID = " + data.inst._get_parent(data.rslt.obj).attr("id")); 

      var parent = data.inst._get_parent(data.rslt.obj); 
      alert("Selected node Parent Text = " + parent.find('a').first().text()); 
      alert("Selected node Parent Tag a title:" + parent.find('a').attr("title")); 

     } 
     ); 

    }); 
</script> 
0
alert("Selected node Tag a title:" + data.rslt.obj.find('a').attr("title")); 
Смежные вопросы