avoscloud-tree

storing hierarchical data in avoscloud

Usage no npm install needed!

<script type="module">
  import avoscloudTree from 'https://cdn.skypack.dev/avoscloud-tree';
</script>

README

Hierarchical Data 必须要有三个字段:
  • tree:定义树
  • parent:定义父节点
  • lft:左标记
  • rgt:右标记
数据结构及算法设计来源于教程:

https://www.sitepoint.com/hierarchical-data-database/
https://www.sitepoint.com/hierarchical-data-database-2/
https://www.sitepoint.com/hierarchical-data-database-3/

异步设计来源教程:

http://es6.ruanyifeng.com/#docs/async
http://www.tuicool.com/articles/qMz2iyj

使用方法:
1.添加节点
AVObjectTree.addNode(className, tree, parent)
2.初始化节点
var node = new AVObjectTree(className, objectId)
3.获取节点
node.fetch()
.then(avobject=>{code...})
.catch(err=>{code...})
4.删除节点及其所有子节点(节点的树)
node._deleteNode()
.then(()=>{code...})
.catch(err=>{code...})
5.获取节点路径(节点到树根的路径上所有节点,节点的所有父节点)
node._pathNode()
.then(parentNodes=>{code...})
.catch(err=>{code...})
6.获取的直接相连的父节点
node._parentNode()
.then(parentNode=>{code...})
.catch(err=>{code...})
7.获取节点的树结构(节点及其所有子节点,并成树状结构)
node._displayNode()
.then(tree=>{code...})
.catch(err=>{code...})
8.获取节点的直接相连的子节点
node._subNode()
.then(childNodes=>{code...})
.catch(err=>{code...})
9.获取节点的所有子节点
node._childNode()
.then(childNodes=>{code...})
.catch(err=>{code...})