⬆️ ⬇️

JsTree - trees are so easy

Hello!



On the JsTree plugin on Habré was mentioned only in the distant 2009. Since that time, everything has changed quite a bit. The plugin is actively developing. Project page on githaba .



Considering the specifics of the project I am working on (reference system), this plugin turned out to be simply irreplaceable, and I use 90% of its functionality with great pleasure. And I still have not seen the same powerful alternative.

')





If you need to just draw a tree in the browser, then of course you can use other plugins, or write it yourself and concisely, but for a wider functionality - JsTree is just a great option.



What we have?







How does it work?



Excellent and clear examples can be found on the official website. Detailed documentation is also present .



To get started, we need to connect jquery.js, jstree.js (180KB uncompressed) and a folder with themes (it connects with the plugin itself, just put it next)



I will give an example of using a tree based on JSON.



HTML:
<div id="tree"></div> 


Jquery:
 $("#tree") .bind("before.jstree", function (e, data) { //       }) .jstree({ //   "plugins" : [ "themes","json_data" ], "json_data" : { "ajax" : { "url" : "tree.php", //   JSON "data" : function (n) { //   } } }, }) .bind("select_node.jstree", function(e, data){ //     //        window.location.hash = "view_" + data.rslt.obj.attr("id").replace("node_",""); }) }); 


We get a simple tree in the spirit of examples



Perhaps I will not describe the sheet from other examples. You can read them on the official website, but if you have any specific questions on the topic, I will answer with pleasure.

Source: https://habr.com/ru/post/151239/



All Articles