Hello. I understand how to import a javascript library using, for example,
But I do not understand how to import a javascript library like jstree that does not provide a library name. A simple call to jstree in the body of a html page would be:
<body> <div id="tree_div"> <ul> <li>Root node 1 <ul> <li id="child_node_1">Child node 1</li> <li>Child node 2</li> </ul> </li> <li>Root node 2</li> </ul> </div> <button>demo button</button>
<script src="dist/libs/jquery.js"></script> <script src="dist/jstree.min.js"></script>
<script> tree1 = $(function () {
$('#tree_div').jstree();
}); </script>
</body>
I can load the object tree1 in brython via tree1 = window.tree1, but it does not have functionality. That is, no methods are exposed as far as I can tell. `tree1` has attributes ['0', 'length'],
and tree1['0'] has attributes ['$brython_id', 'jQuery331087540390626656961', 'location']. The jquery attribute has attributes like 'event' and 'handle'.
Alternatively, I can use this in the html instead:
<script> tree2 = $('#tree_div').jstree();</script>
and then tree2 does have methods to call via Brython. But I don't understand how to bind events to it. In javascript, you would use something like:
$('#tree_div').on("changed.jstree", function (e, data) { console.log(data.selected); });
But in Brython, the following has no effect:
def on_tree_change(evt):
alert ("tree changed")
document['tree_div'].bind("changed.jstree", on_tree_change)
Nor does
document['tree_div'].bind("changed", on_tree_change) have any effect.
I imagine the solutions are very simple, but I'm not sure how to get this javascript tree library working with Brython. Any suggestions?