| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This library allows you to deal with deep nested arrays in JavaScript.
Navigate into nested collections can be tricky, so NestedJS try to get it easier.
You can find a live demo of NestedJS here.
Download the latest version of NestedJS and load the file Nested.min.js (on build folder) on your HTML page :
<script src="/path/to/Nested.min.js"></script>You just have to install ...
# with NPM
$ npm install nestedjs
# with Yarn
$ yarn add nestedjs... and load the package on your script
const NestedJS = require('nestedjs')
// OR
import NestedJS from 'nestedjs'Once package loaded, NestedJS must ne instanciate with a nested collection.
const collection = [...] // Nested data collection
const tree = new NestedJS(collection)IMPORTANT : The property of every node's children if there are, is named children by default. You can change the name with the option children_key.
The created instance transform the collection and add several properties and methods to each collection's node :
To know the added properties on each node you must debug your collection, or you can simply browse it with a recursive loop.
You can retrieve a node by his unique id :
const node = tree.retrieveNode(/* __nodeid node unique id */)This will returns a node which is an instance of the NestedJS's Node class. This class has several methods :
node.properties node.getId() node.getParentId() node.getNextId() node.getPreviousId() node.hasProperty(key) node.getProperty(key, defaultValue) node.setProperty(key, value) node.previousNodes() node.previousNode() node.hasPreviousNode() node.nextNodes() node.nextNode() node.hasNextNode() node.siblingsNodes() node.childNodes() node.firstChild() node.lastChild() node.nthChild() node.hasChildNodes() node.parentNode() node.hasParentNode() node.rootNode() node.hasRootNode() node.breadcrumb() node.getTree() node.depth()Each node original properties are preserved and are transferred as properties of the NestedJS's Node class.
You also retrieve one or several nodes by a key/value couple search :
const nodes = tree.retrieveNodesBy('name', 'lorem')| Back | FazBrowse Home | New Git URL |