使用element-ui中的树型表格,父子id有重复
在使用element-ui中的树型表格,当父子id存在重复,而row-key绑定的是id,此时在浏览器界面会出现warning。
此时,可以通过row-key动态绑定函数,在函数中通过是父亲还是孩子,来对id做一点点的修改,返回给row-key即可。
在表格中,如下:
<el-table
:data="type"
style="width: 100%"
:row-key="row=>getRowKey(row)"
border
default-expand-all
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
>
在方法中如下:
getRowKey(row){
if(row.children!==undefined) return row.id+'only';
return row.id;
},
此时,问题就得到解决了。