Hi i have problem with getting data of selected node of jstree model.
<script type="text/javascript">
$('#preview').on("changed.jstree", function (e, data) {
console.log(data.selected);
console.log(data.selected.attr("text"));
});
</script>
the first console log shows me "[js1_1]" or "[js1_2]" depending on the selected node. But The second log "undefined is not a function" ;/ I have tried many different ways but i failed to achieve getting node text(title) or any other info
I send list of models as json and it looks like this:
Public Class JsTreeModel
Public Property text As String
Public Property icon As String
Public Property Id As String
Public Property PId As String
Public Property ParentId As String
Public Property Status As Integer
End Class
anyone has solution ?
UPDATE jstree code
<script type="text/javascript">
$(document).ready(function () {
$('#WhenRemoving').toggle($('.RemoveCheckbox').is(":checked"));
$('#WhenAdding').toggle(!$('.RemoveCheckbox').is(":checked"));
$('#preview').jstree({
'core': {
'data': {
'url': '/TreeTest/TreePreview/',
'data': function (node) {
return node;
}
}
}
}).bind("loaded.jstree", function (event, data) {
$(this).jstree("open_all");
})
});
</script>
when i add this to my jstree i can see selected name node in html div
.on('changed.jstree', function (e, data) {
var i, j, r = [];
for (i = 0, j = data.selected.length; i < j; i++) {
r.push(data.instance.get_node(data.selected[i]).text);
}
$('#event_result').html('Selected: ' + r.join(', '));
})
});
None above worked for me. This worked:
$(treeID).jstree().get_selected(true)[0].text;
instead of
data.selected.attr("text")
try this
data.selected.text()
You can also get selected jstree
node text with this :
console.log($("#preview").jstree("get_selected").text());
OR just bind select_node.jstree
as shown
.bind("select_node.jstree", function (NODE, REF_NODE) {
var a = $.jstree._focused().get_selected();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With