Frage

I am using jstree in demo .i want to get information of child.I want to get id of children whenver user click there parent node.

here is my expected output

  • 1) "a" element don't have child so if user click on it it array is null;
  • 2) "b" element have two child "b-a","b-b" .so if user click on it it array id of these two element;
  • 3) "b-a" element don't have child so if user click on it it array is null;
  • 4) "b-b" element have two child "b-b-a","b-b-b" .so if user click on it it array id of these two element; fiddle http://jsfiddle.net/fuu94/8/

    $(document).ready(function () {

    $('#tree').on("select_node.jstree", function (e, data) {
        alert("node_id: " + data.node.id);
        $('#tree').jstree(true).toggle_node(data.node);
    
        var selEl = [];
        $(this).siblings().each(function (idx, el) {
            selEl.push($(el.node).attr("id"));
        });
        console.log(selEl);
    });
    $('#tree').jstree({
        "core": {
            "check_callback": true
        },
        "plugins": ["dnd"]
    });
    $('#home').click(function () {
        alert('home');
    
    });
    $('#next').click(function () {
        alert('next');
    
    });
    $('#pre').click(function () {
        alert('pre');
    
    });
    

    });

War es hilfreich?

Lösung

Updated Answer

Get children id:

$(data.node.children).each(function(index, item){
    console.log(item);  // <-- logs the item id to console
});

Get root nodes when home is pushed:

$('#home').click(function () {
    var rootChildren = $('#tree').find('ul > li');
    $(rootChildren).each(function(index, item){
        console.log(item.id); // <-- logs root node id to console
    });
    //alert('home');
});

Updated fiddle

Original Answer

Use

data.node.children

ex.

$('#tree').on("select_node.jstree", function (e, data) {
    var nodeChildren = data.node.children;  // <- get children
    .
    .
    .
});

Updated your fiddle to alert children instead of id - updated fiddle

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top