Giter VIP home page Giter VIP logo

backbone-tree-view's Introduction

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: -->
        <link href="./node_modules/backbone-tree-view/node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
        <script src="./node_modules/backbone-tree-view/node_modules/jquery/dist/jquery.min.js"></script>
        <script src="./node_modules/backbone-tree-view/node_modules/underscore/underscore-min.js"></script>
        <script src="./node_modules/backbone-tree-view/node_modules/backbone/backbone.js"></script>
        <script src="./node_modules/backbone-tree-view/node_modules/backbone-tree-model/src/backbone.treemodel.js"></script>

        <!--Backbone-tree-view: -->
        <link href="./node_modules/backbone-tree-view/css/bootstrap-theme.min.css" rel="stylesheet">
        <script src="./node_modules/backbone-tree-view/lib/backbone-tree-view.js"></script>
  • Add container inside BODY:
<body>
	<div id="tree"></div>
</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 = new BackTree.Collection([
        {
            id:7,
            title:'No children'
        },
        {
            id:1,
            title:'Australia',
            open : false,
            nodes: [
                {
                    id: 2,
                    title : 'Sydney'
                }
            ]
        },
    ]);
  • Create tree:
	var tree = new BackTree.Tree({
	    collection : data
	});
  • Render and append:
	$('#tree').append(tree.render().$el);

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 = new BackTree.Tree({
	    collection : data,
	    settings : {
			plugins : {
                DnD: {}
            }
	    }
	});

Possible options:

  • changeParent - (boolean) - if false only sorting will be available.

Example:

	var tree = new BackTree.Tree({
	    collection : data,
	    settings : {
			plugins : {
                DnD: {
                    changeParent : false
                }
            }
	    }
	});

How to serialize tree?

	var collection = new BackTree.Collection([
        {
            id:7,
            title:'No children'
        },
        {
            id:1,
            title:'Australia',
            open : false,
            nodes: [
                {
                    id: 2,
                    title : 'Sydney'
                }
            ]
        },
    ]);

	var tree = new BackTree.Tree({
	    collection : collection,
	    settings : {
			plugins : {
                DnD: {}
            }
	    }
	});

    console.log(collection.toJSON());

Checkboxes:

	var tree = new BackTree.Tree({
	    collection : collection,
	    settings : {
			checkbox : true
	    }
	});

Get all checked:

	collection.where({checked:true}, {deep:true});

backbone-tree-view's People

Contributors

kirill-zhirnov avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.