I've been struggling all night and can't seem to get a list of checked checkbox items back from jstree.
The tree works fine and loads the data from my web service and the selected items from the data are selected but when I come to save the checked ID's into the DB I am finding that only the child ID's are getting returned. My data looks something like this:
{"id":"2","parent":"#","text":"Trade Policy Group","state":{"opened":false,"selected":true},"li_attr":{"ID":"2"}},{"id":"3","parent":"#","text":"Environmental Policy Group","state":{"opened":false,"selected":false},"li_attr":{"ID":"3"}},{"id":"4","parent":"#","text":"Digital Economy Policy Group","state":{"opened":false,"selected":false},"li_attr":{"ID":"4"}},
And my js code:
$( document ).ready(function () {
$('#jstree').on("changed.jstree", function (e, data) {
$('[name$="CategoryListHidden"]').val(data.selected);
console.log(data.selected);
});
var cl = '[[CategoryList]]';
if(cl==''){cl=0}; // if no categories then use a zero
var url = 'http://de_webservices.mybox.me/api/JsonCategories?NewsItemIds=' + cl + '&formMode=EDIT';
$('#jstree').jstree({
"checkbox": {
"keep_selected_style": false,
"visible" : true,
"three_state": true,
"whole_node" : true,
},
"plugins": ["checkbox"],
'core' : {
'dataType': "jsonp",
'data': {
'url': url,
'data': function(node) {
return { 'id': node.id };
}
}
}
});
$("#getChecked").click(function () {
$("#jstree").jstree("get_checked", null, true).each(function (i, e) {
console.log($(this).attr("ID"))
});
});
});
I am using the latest jstree code. I am wondering if it's to do with the li_attr or something. Can anyone spot anything obvious?
thanks
Gus