Generic TreeView component. It generates a tree view with expand/collapse functionality based in a JS object or JSON coming from AJAX.
Node.js Local server and environment, Webpack Module loader and task manager, eslint Javascript linter, Babel ESnext transpiler. jQuery DOM library.
├── /app/ # The source code of the application
│ ├── /modules/ # JS modules
│ ├── /styles/ # Main Styles of the application
│ └── index.js # Entry point for the JS modules
│── /build/ # The application final output
├── /node_modules/ # Node.js modules
│── .editorconfig # Config file to keep standards for text editors
│── .gitignore # Git ignore rules
│── .seslintrc # Eslint confi file
│── package.json # The node.js modules dependencies file
└── README.md # Important information related
Make sure you have Node.js installed. Run:
$ npm install$ npm start # Starts webpack-dev-server with hot reloading$ npm run build # Generates the final assets inside the build folderImport the TreeView component.
import TreeView from './modules/TreeView';Init the component (inline data)
const topView = new TreeView({
data: TreeData(),
wrapper: '.topTreeView',
nodeClass: 'node',
keyLabel: 'title',
keyChildren: 'childs',
toggleEffect: 'slide'
});Init the component (ajax)
const bottomView = new TreeView({
ajax: true,
url: 'data/treeData.html',
wrapper: '.bottomTreeView',
nodeClass: 'node',
keyLabel: 'label',
keyChildren: 'items',
toggleEffect: 'fade'
});object Object passed to the TreeView with the data. Must be a valid JS Object.
object Enable to fetch the data via AJAX
object Url to fetch the data with AJAX. This is required if ajax option is passed
string Class or ID to the wrapper to insert the Treeview component
string CSS Class to apply each tree view node
string Key of the title of each node in the object
string Key to access the children in the object
string Effect to display/hide the items
fade Fade Effect
slide Slide Effect
Return the number of nodes in the TreeView
Collapse the TreeView completely
Expand all the TreeView nodes
Open or close the item passed
item Should have the node element to toggle