怎样设置ElementUI table标签只展示2个层级呢?

我设置了:row-key和expand-row-keys但是只显示了一个层级
https://element.eleme.cn/#/zh...
image.png
想要这样显示2个级别:
image.png

数据结构:
image.png
image.png
image.png
image.png
每个children里面都是嵌套children每个对象里都有id和children
代码:
` <el-table

  v-loading="loading"
  :data="deptList"
  row-key="deptId"
  :expand-row-keys="rowKey"
  :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>`



阅读 5.7k
2 个回答

那个方法没有成功。换了个方法就成功了!
`

<el-table
  ref="deptTab"
  v-loading="loading"
  :data="deptList"
  row-key="deptId"
  :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>`
`  updated() {
if(this.$refs.deptTab && this.deptList.length > 0) {
  this.$refs.deptTab.toggleRowExpansion(this.deptList[0], true);
}

},`

成功!

我怀疑是tree-props的配置有点问题把,官方的例子确实是这么写的没错,但是你得根据实际情况来修改一下。

{ hasChildren: 'hasChildren', children: 'children' }

当中,hasChildren绑定一个值,相当于,row.hasChildren判断是否展开;children绑定一个值,相当于,row.children为展开的子数据。假如row当中没有hasChildren这个属性的话,那就是undefined自然也就不会展开了
我觉得你可以试试不要这个props,因为你也没设置懒加载的功能(本人没试过,你可以尝试一下)
image

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题