当前位置:网站首页>[pit avoidance refers to "difficult"] halfcheckedkeys rendering problem in semi selected status of antd tree
[pit avoidance refers to "difficult"] halfcheckedkeys rendering problem in semi selected status of antd tree
2022-06-25 13:15:00 【Coconut brine Engineer】
One 、 Repetition problem
Antd Of Tree Tree components , After checking , If all child nodes under the parent node are not checked ( Semi selected state ), Values are not transferred to the parent node , Only when all child nodes are checked ( Select all ) The value of the parent node .
Two 、 Solution
1) In the half selected state , Also pass the value of the parent node to the backend
const [checkedKeys, setCheckedKeys] = useState<number[]>([]);
const [treeData, setTreeDate] = useState([]);
const [paramsList, setParamsList] = useState([]);
const [initialList, setInitialList] = useState([]);
<Tree checkable onCheck={
onCheck} checkedKeys={
checkedKeys} treeData={
treeData} />
adjustment onCheck() Method :
const onCheck = (keys: any, e: any) => {
let arr = keys.concat(e.halfCheckedKeys)
setParamsList(arr) // Pass value to backend , It includes the semi selected parent nodes
setCheckedKeys(keys);
};
halfCheckedKeys: The parent node in semi selected status will be recorded
2) Echo rendering problems
useEffect(() => {
const {
location: {
query }}: any = history;
setRoleId(query.roleId);
queryAuth(query.roleId);
}, []);
const queryAuth = async (id: any) => {
const list = await getAuthUser(id); // Get the list data through the interface
const listData = list.data;
setTreeDate(listData);
let visibleList = [] as any;
function lookUserAuth(data = [], arr = []) {
for (let i = 0; i < data.length; i++) {
if (data[i].visible === 0) {
//0 Choose ,1 Not selected
if (data[i].children && data[i].children.length){
data[i].children.map((i: any)=>{
visibleList.push(i.visible)
if(visibleList.includes(1)){
return
}
else{
arr.push(i.key);
}
})
}
else{
arr.push(data[i].key);
}
}
if (data[i].children && data[i].children.length)
lookUserAuth(data[i].children, arr)
}
return arr
}
setCheckedKeys(lookUserAuth(listData));
};
边栏推荐
- 康威定律,作为架构师还不会灵活运用?
- Germany holds global food security Solidarity Conference
- Lexical trap
- [flask tutorial] flask overview
- mysql导入导出数据到excel表日期出现问题
- Configuring pytorch in win10 environment
- New Gospel of drug design: Tencent, together with China University of science and technology and Zhejiang University, developed an adaptive graph learning method to predict molecular interactions and
- You can't specify target table 'xxx' for update in from clause
- 揭秘GaussDB(for Redis):全面对比Codis
- Wechat full-text search technology optimization
猜你喜欢

Introduction to mongodb chapter 01 introduction to mongodb

leetcode - 384. 打乱数组

KDD 2022 | graphmae: self supervised mask map self encoder

Golang keyboard input statement scanln scanf code example

Possible problems when idea encounters errors occurred while compiling module (solved)

An article clearly explains MySQL's clustering / Federation / coverage index, back to table, and index push down

It is extraordinary to make a move, which is very Oracle!

指针,它那些不得不说的题目

Sword finger offer day 2 linked list (simple)

Capabilities required by architects
随机推荐
KDD 2022 | GraphMAE:自监督掩码图自编码器
Stockage des données en mémoire
剑指 Offer II 025. 链表中的两数相加
Wechat full-text search technology optimization
Serevlt初识
1024水文
指针,它那些不得不说的题目
And console Log say goodbye
Module 5 (microblog comments)
药物设计新福音:腾讯联合中科大、浙大开发自适应图学习方法,预测分子相互作用及分子性质
數據在內存中的存儲相關內容
JSTL tag: fmt:formatdate tag format Chinese standard time or timestamp
数据在内存中的存储相关内容
Capabilities required by architects
Sword finger offer II 029 Sorted circular linked list
New Gospel of drug design: Tencent, together with China University of science and technology and Zhejiang University, developed an adaptive graph learning method to predict molecular interactions and
关于结构体,枚举,联合的一些知识
Golang keyboard input statement scanln scanf code example
A half search method for sequential tables
Koa 框架