Pergunta

I want to get all parent node text . when user Click home button it should give parents node elemnent not id of that ? I am using jstree .

In my demo Expected out put is "a" and "b". ?

   $('#home').click(function () {
         alert('home');
          alert($('#tree').jstree(true).get_node('null').children);

    });

http://jsfiddle.net/fuu94/40/

Foi útil?

Solução

Try this:

$('#home').click(function () {
    var roots = $('#tree').jstree(true).get_children_dom($('#tree'));
    roots.each(function(x, k) { alert(k.id); });
});

In the function each, you get the IDs of the root nodes, so you should add your code there.

If you want the text of the root nodes, you can use the function get_text for each nodes that we identified before:

$('#home').click(function () {
    var tree = $('#tree').jstree(true);
    var roots = tree.get_children_dom($('#tree'));
    roots.each(function(x, k) {
        alert(tree.get_text($('#'+k.id)));
    });
});

Code in Fiddle: http://jsfiddle.net/fuu94/41/

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top