百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
V

vanillatree

> 编程语言
开源

Vanilla.js 替换 jstree

99 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Vanilla.js 替换 jstree

vanillatree

Standalone tree view library

Live demo

Usage

For CJS env run npm install --save vanillatree:

javascript
const VanillaTree = require('vanillatree');
javascript
// treeElement is selector or HTML node, options is optional
const tree = new VanillaTree(treeElement, options);

Options

  • placeholder (string) -- shows if none of leafs is added (optional)
  • contextmenu (array) -- contextual menu items (optional)

Examples

javascript
const tree = new VanillaTree('.my-selector', {
  placeholder: 'No leaf is added yet',
  contextmenu: [{
    label: 'Label 1',
    action(id) {
      // someAction
    }
  },{
    label: 'Label 2',
    action(id) {
      // someAction
    }
  }]
});

Methods

  • add(options) -- Adds a leaf. id option is optional
  • move(id, parentId) -- Moves a leaf to another parent
  • remove(id) -- Removes a leaf with given id
  • open(id) -- Expands child tree
  • close(id) -- Closes child tree
  • toggle(id) -- Expands or closes child tree depending on current state
  • select(id) -- Selects a leaf with given id

Examples

javascript
tree.add({
  label: 'Label A',
  id: 'a',
  opened: true,
  selected: true
});

tree.add({
  label: 'Label B',
  id: 'b',
  parent: 'a'
});

tree.open('a');

Events

VanillaTree uses dispatchEvent for events triggering. Each event is cancelable and bubbles up through the DOM. An id of a target element is placed at evt.detail object.

A list of possible events:

  • vtree-add
  • vtree-move
  • vtree-remove
  • vtree-open
  • vtree-close
  • vtree-select

Examples

javascript
treeElement.addEventListener('vtree-open', (evt) => {
  info.innerHTML = evt.detail.id + ' is opened';
});

treeElement.addEventListener('vtree-close', (evt) => {
  info.innerHTML = evt.detail.id + ' is closed';
});

treeElement.addEventListener('vtree-select', (evt) => {
  info.innerHTML = evt.detail.id + ' is selected';
});

Image sprite is the part of JSTree project

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言