I'm currently using js tree. I want to get the all selected node object.
Following is how I populate my jstree.
My JS Code
$(function () {
$('#data').jstree({
'core': {
'data': [
{
"text": "Administration",
"children": [
{
"text": "Admin",
"children": [
{
"text": "Access",
"children": [
{ "id": "1", "text": "Add" },
{ "id": "2", "text": "Edit" },
{ "id": "3", "text": "Delete" },
]
},
]
}
]
}
]
},
'checkbox': {
three_state: false,
whole_node: false, // should be set to false. otherwise checking the hidden checkbox
// could be possible by clicking the node
tie_selection: false, // necessary for whole_node to work
cascade: 'up down'
},
'plugins': ["checkbox"]
},
).bind("loaded.jstree", function (event, data) {
$(this).jstree("open_all");
$('.btnGetCheckedItem').click(function () {
var checked_ids = [];
var selectedNodes = $('#data').jstree("get_selected", true);
console.log(selectedNodes);
$.each(selectedNodes, function () {
/* console.log(this.original);*/
checked_ids.push(this.id);
});
$('#idshow').text(checked_ids);
});
});
});
HTML
<div id="data"></div>
<input class="btnGetCheckedItem" value="Get all checked items" type="button" />
I am trying this code but I am not getting the selected node object. I am taking this from the jstree documents Please let me know if you have any idea where I am doing something wrong?
Thank you