vakata / jstree

jquery tree plugin
http://jstree.com
MIT License
5.15k stars 1.38k forks source link

instantiate jstree on a DOM element (ES6) #2619

Closed tacman closed 2 years ago

tacman commented 2 years ago

is there a way to import or require jstree, and then instantiate it on a dom element?

That is, something like

require('jstree');
// or import { jstree } from 'jstree';

let el = ...
var t = jstree(el);

I imagine this will be more standardized in version 4, without jQuery, but maybe there's a way to do this now. Thanks.

vakata commented 2 years ago

jstree 3 has a module definition (I believe the term was UMD) - that was way before ES6 and standard modules. It can be required but not as a standard module. And v3 always lives inside jQuery - so jQuery.jstree. I hope this answers the question - if not - please clarify.

tacman commented 2 years ago

I found this while searching:

 let $el = jQuery.jstree.reference(el);

where el is a DOM element, not a jquery selector. It didn't work, but it makes me think there's something like it.

For now, I'm just instantiating the tree with

    let $el = $(el);
    this.$element.jstree();

Any status update on the version that doesn't require jquery?