Skip to content

列表溯源主键

js
arrayNode(array, id, [options])

根据主键的值从列表中溯源,返回从根到自身顺序的主键数组,如:[id1, id12, id121]

参数

参数类型默认说明
arrayarray列表结构数据
idany主键的值,如:chartIndexActiveMy
optionsobject配置选项

返回

参数类型说明
*array从根到自身顺序溯源的主键数组

示例

js
import { arrayNode } from '@axolo/tree-array'

const array = [{
  id: 'chart',
  path: '/chart',
  parentId: null
}, {
  id: 'chartIndex',
  path: '/chart/index',
  parentId: 'chart'
}, {
  id: 'chartIndexActive',
  path: '/chart/index/active',
  parentId: 'chartIndex'
}, {
  id: 'chartIndexActiveMy',
  path: '/chart/index/active/my',
  parentId: 'chartIndexActive'
}, {
  id: 'chartReview',
  path: '/chart/review',
  parentId: 'chart'
}, {
  id: 'chartProject',
  path: '/chart/project',
  parentId: 'chart'
}, {
  id: 'smile',
  path: '/smile',
  parentId: null
}, {
  id: 'smileIndex',
  path: '/smile/index',
  parentId: 'smile',
  test: true
}]

arrayNode(array, 'chartIndexActiveMy') // array of id
json
[
  "chart",
  "chartIndex",
  "chartIndexActive",
  "chartIndexActiveMy"
]

@axolo/tree-array