Leanote's Blog
I love Leanote!
Toggle navigation
Leanote's Blog
Home
Chrome
Git
Linux
Windows
Others
工具大全
VsCode
Expo
Html
JavaScript
Npm
Node
Mock
React-Native
React
TypeScript
小程序
插件
正则
Dva
Ant-Design-React
Umi
Vue
Vux
Ant-Design-Vue
Http
Java
flutter
开发小工具
About Me
Archives
Tags
Tree组件子节点不完全勾选获取父节点的值
2023-03-06 18:48:29
24
0
0
admin
### 父节点如果有回显的情况下 1.循环遍历出最深层子节点,存放在一个数组中 2.将后台返回的含有父节点的数组和第一步骤遍历的数组做比较 3.如果有相同值,将相同值取出来,push到一个新数组中 4.利用这个新的重组的数组给Tree组件selected赋值 ``` const deepArr = [] //deepArr存放所有子节点的数组 //第一步骤:子节点放在一个数组中 const requestList = (data) => { data && data.map(item => { if (item.children && item.children.length > 0) { requestList(item.children) } else { deepArr.push(item.id) } return null }) return deepArr } //第2,3步骤的方法 const uniqueTree = (uniqueArr, Arr) => { let uniqueChild = [] for (var i in Arr) { for (var k in uniqueArr) { if (uniqueArr[k] === Arr[i]) { uniqueChild.push(uniqueArr[k]) } } } return uniqueChild } //调用第2,3步骤的方法 const getRoleInfo = () => { getData({ id: Id }).then(res => { const ids = res.data const uniqueChild = this.uniqueTree(ids, deepArr) setCheckedKeys(uniqueChild) }) } <Tree checkable checkedKeys={checkedKeys} defaultExpandedKeys={checkedKeys} fieldNames={{ title: 'name', key: 'id' }} treeData={menuList} /> ```
Pre:
any,never,void和unknown的区别
Next:
submodule使用笔记
0
likes
24
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.