JsTree: binding to domain objects

I want to associate each node in my tree with a domain object. I passed HTML data and manually saved the domain object in jQuery data:

$('li node description').data('obj', my_domain_object);

However, it seems that jsTree is clearing the data in time $('#jstree_div').jstree();.

So $('li node description').data('obj')- undefined.

What is the best practice? (I assume that the principle will be the same for HTML or JSON data)

+4
source share
1 answer

jsTree keeps the data intact, but moves it for optimization reasons [1]. Therefore, in the callback, it must be accessible via data.node.data.some_key. In my example, the magic spell was:

$('#jsTree_div').on('select_node.jstree', function (e, data) {
        data.node.data.obj //... (instead of $('#node_id').data('obj'))
});

[1] " - . jQuery".data() " , node, ". - , jsTree https://groups.google.com/d/msg/jstree/w97E8uG_Bd0/enYklH-B1-cJ

+1

All Articles