backbone-tree-view
Backbone.View component which provide interactive tree.
Demo
http://kirill-zhirnov.github.io/backbone-tree-view/
How to install?
npm install backbone-tree-view
- Add scripts and styles inside HEAD tag:
<!--Dependencies: --> <!--Backbone-tree-view: -->
- Add container inside BODY:
- Prepare array for collection:
var data = id:7 title:'No children' id:1 title:'Australia' open : false nodes: id: 2 title : 'Sydney' ;
Or you can create collection:
var data = id:7 title:'No children' id:1 title:'Australia' open : false nodes: id: 2 title : 'Sydney' ;
- Create tree:
var tree = collection : data ;
- Render and append:
;
Data structure:
var data = id:7 title:'No children' id:1 title:'Australia' open : true checked : true nodes: id: 2 title : 'Sydney' ;
Possible keys:
-
nodes - (Array) - Array with children.
-
open - (boolean) - If leaf has child - it will be opened.
-
checked - (boolean) - If tree has checkboxes - checkbox will be checked.
Drag and drop
var tree = collection : data settings : plugins : DnD: {} ;
Possible options:
- changeParent - (boolean) - if false only sorting will be available.
Example:
var tree = collection : data settings : plugins : DnD: changeParent : false ;
How to serialize tree?
var collection = id:7 title:'No children' id:1 title:'Australia' open : false nodes: id: 2 title : 'Sydney' ; var tree = collection : collection settings : plugins : DnD: {} ; console;
Checkboxes:
var tree = collection : collection settings : checkbox : true ;
Get all checked:
collection;