Jquery – JsTree .get_checked function doesn’t work… help….

asp.net-mvcjqueryjquery-pluginsjstree

I'm using JSTree and checkbox plugin, but I couldn't managed to pick the nodes selected (checked), I read in the JSTree documentation about the event .get_checked, but do not know how to implement it, neither the place to put it, if within the function where data is loaded or not, also I don't understand that when the event works, ie I do not know if the event is executed each time a node is checked or have an array that is filled every time a node is chcked… please help me … the truth I'm lost and do not know how to do that.

Here's my Jscript code, the load of data is fine, but the get_checked function doesn't work…

$(function () {
    $("#demo2")
        .jstree({
             plugins: ["themes", "json_data", "checkbox", "crrm"],
                   "json_data": {
                    "ajax": {
                        "type": "POST",
                        "url": "/Ubicacion/Arbol/",
                        "data": function (n) { return { id: n.attr ? n.attr("id") : 0} }
                }
            }

            })

        .bind("check_node.jstree", function (event, data) {
            alert($.jstree._focused().get_checked().attr('id'));
        })

    });

Searching around internet I found a "middle" solution:

 $(function () {
        $("#demo2")
        .jstree({

            plugins: ["themes", "json_data", "checkbox", "crrm"],
            "json_data": {
                "ajax": {
                    "type": "POST",
                    "url": "/Ubicacion/GetTreeview/",
                    "data": function (n) { return { id: n.attr ? n.attr("id") : 0} }
                }
            }
        }).bind('check_node.jstree', function (e, data) {
            alert("Nodo elegido " + data.rslt.obj.attr("id"));
        });
    });

I add these lines:

.bind('check_node.jstree', function (e, data) {
                alert("Nodo elegido " + data.rslt.obj.attr("id"));
            });

and now I had only the parent node, the children doesn't be coleected… any idea..??

please… help me…!!

Best Answer

This is how I call/get all checked nodes

checked = $("#tree").jstree("get_checked",null,true) ;

Works nicely for me. It seems to me that the 'trouble' would be when and how you call .get_checked

Could you tell us what you want to achieve? The best would be if you can provide sample on jsfiddle.net

Update

Working sample is on jsfiddle

1) how you bind action to checking the checkbox

$("#jstree").bind('check_node.jstree', function(e, data) {
    $("#list").append('<BR>clicked and ' + node_is_check(data));
});

2) how to check if a checkbox is checked, where object = data from above

object.inst.is_checked(object.rslt.obj
Related Topic