Tree 树形组件

在线预览

Maker

  1. maker.tree('权限','rule',[]).props({
  2. data:[], //数据结构参考下面
  3. type:'checked'
  4. })

JSON

  1. {
  2. type:"tree",
  3. title:"权限",
  4. field:"rule",
  5. value:[],
  6. props:{
  7. data:[],
  8. type:'checked',
  9. multiple:false,
  10. showCheckbox:true,
  11. emptyText:'暂无数据'
  12. }
  13. }

参考:iview2.x | iview3.x

value: String | Number | Array

props

属性 说明 类型 默认值
data 可嵌套的节点属性的数组,生成 tree 的数据 Array []
multiple 是否支持多选 Boolean false
show-checkbox 是否显示多选框 Boolean false
empty-text 没有数据时的提示 String 暂无数据
load-data 异步加载数据的方法,见示例 Function -
render 自定义渲染内容,见示例 Function -
children-key 定义子节点键 String children
check-strictly 在显示复选框的情况下,是否严格的遵循父子不互相关联的做法 Boolean false
check-directly 3.3.0 开启后,在 show-checkbox 模式下,select 的交互也将转为 check Boolean false

on 事件

事件名 说明 返回值
on-select-change 点击树节点时触发 当前已选中的节点数组、当前项
on-check-change 点击复选框时触发 当前已勾选节点的数组、当前项
on-toggle-expand 展开和收起子列表时触发 当前节点的数据

props.data 数据结构

  1. [{
  2. title: 'parent 1',
  3. expand: true,
  4. selected: false,
  5. id:1,
  6. children: [
  7. {
  8. title: 'parent 1-1',
  9. expand: true,
  10. id:2,
  11. children: [
  12. {
  13. title: 'leaf 1-1-1',
  14. disabled: true,
  15. id:11
  16. },
  17. {
  18. title: 'leaf 1-1-2',
  19. selected:true,
  20. id:12
  21. }
  22. ]
  23. },
  24. {
  25. title: 'parent 1-2',
  26. expand: true,
  27. id:3,
  28. children: [
  29. {
  30. title: 'leaf 1-2-1',
  31. checked: true,
  32. id:13,
  33. },
  34. {
  35. title: 'leaf 1-2-1',
  36. id:14,
  37. }
  38. ]
  39. }
  40. ]
  41. }]