forked from joaonuno/tree-model-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add installation and configuration instructions to project README.
- Loading branch information
Showing
1 changed file
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,49 @@ | ||
TreeModel | ||
========= | ||
# TreeModel | ||
|
||
Manipulate and traverse tree-like structures in javascript. | ||
|
||
http://jnuno.com/tree-model-js | ||
For download, API and demos, please [visit tree-model-js website](http://jnuno.com/tree-model-js). | ||
|
||
## Instalation | ||
|
||
### Node | ||
TreeModel is available as a npm module so you can install it with `npm install tree-model` and use it in your script: | ||
|
||
``` | ||
var TreeModel = require('tree-model'), | ||
tree = new TreeModel(), | ||
root = tree.parse({name: 'a', children: [{name: 'b'}]}); | ||
``` | ||
|
||
### Browser | ||
#### Using [requirejs](http://requirejs.org/) | ||
``` | ||
<script src="path/to/require.js"></script> | ||
<script> | ||
require(["path/to/TreeModel"], function(TreeModel) { | ||
var tree = new TreeModel(), | ||
root = tree.parse({name: 'a', children: [{name: 'b'}]}); | ||
}); | ||
</script> | ||
``` | ||
#### As a global variable | ||
``` | ||
<script src="path/to/TreeModel.js"></script> | ||
<script> | ||
var tree = new TreeModel(), | ||
root = tree.parse({name: 'a', children: [{name: 'b'}]}); | ||
</script> | ||
``` | ||
|
||
## Configuration | ||
You can pass the property name of the children array and a comparator function to be used by `parse` and by `addChild`: | ||
``` | ||
var tree = new TreeModel({ | ||
// Default is 'children' | ||
childrenPropertyName: 'dependencies', | ||
modelComparatorFn: function (a, b) { | ||
// Reverse order by name | ||
return a.name < b.name; | ||
} | ||
}); | ||
``` |