当前位置:网站首页>In JS, t, = > Analysis of
In JS, t, = > Analysis of
2022-04-23 17:44:00 【Front Thoughts】
data:
var t = [{
nodeCode: '59',
nodeName: ' International Primary School ',
children: [{
nodeCode: '37',
nodeName: 'PYP Primary school ',
children: [{
nodeCode: '99',
nodeName: ' second grade ',
children: null,
billOpened: null,
},
{
nodeCode: '100',
nodeName: ' Third grade ',
children: null,
billOpened: true,
},
{
nodeCode: '101',
nodeName: ' Fourth grade ',
children: null,
billOpened: true,
},
{
nodeCode: '102',
nodeName: ' Fifth grade ',
children: [{
nodeCode: '1011',
nodeName: ' Class one ',
children: null,
billOpened: true,
}, ],
billOpened: true,
},
],
billOpened: true,
}, ],
billOpened: true,
},
{
nodeCode: '59',
nodeName: ' International Primary School ',
children: [{
nodeCode: '37',
nodeName: 'PYP Primary school ',
children: [{
nodeCode: '99',
nodeName: ' second grade ',
children: null,
billOpened: null,
},
{
nodeCode: '100',
nodeName: ' Third grade ',
children: null,
billOpened: true,
},
{
nodeCode: '101',
nodeName: ' Fourth grade ',
children: null,
billOpened: true,
},
{
nodeCode: '102',
nodeName: ' Fifth grade ',
children: [{
nodeCode: '1011',
nodeName: ' Class one ',
children: null,
billOpened: true,
}, ],
billOpened: true,
},
],
billOpened: true,
}, ],
billOpened: true,
},
];
const recUpdate = (t, f) =>({
...t, children: t?.children?.map(c => recUpdate(c, f)), ...f(t) })
const formatBillOpened = t =>recUpdate(t, _ => ({
billOpened: false }))
formatBillOpened(t)
console.log(t)
recUpdate(t, _ => ({ billOpened: false })) It's an arrow function. I'm confused , Why use this _ As a function parameter ? Later, I checked the information , not have understood until then , Under normal circumstances , If we write an arrow function that does not require parameters , This is how it is written
recUpdate= () => {/ Code /}
1
If we use () How to write it , This arrow function will not pass arguments , If the underline is used as a parameter
recUpdate(t, _ => ( {/ Code /})
2
After a search , Confirmed that this is a reference golang Variable Underlined ideas
In a nutshell , This is this. recUpdate Function can have a parameter , Just use _ To express , But internally executed code does not call parameters , That is, no interest in parameters . It can also be understood as , This variable must be filled in when using the arrow function , But I don't want to use , I'm too lazy to name , Avoid making information noise .
() and _ These two ways of writing , The same functions are realized , But now I prefer to use _, because _ And () comparison , Occupy fewer pixels , There is a better way , Ignore the meaning of this variable !
Global modification t Array billOpened by false
let loop = (t) => {
t.map(item => {
item.billOpened = false
item.children && loop(item.children)
})
}
loop(t)
console.log(t)
let strT=JSON.stringify(t).replace(/\s+/g,"");
let result=strT.replaceAll("\"billOpened\":true", "\"billOpened\":false")
console.log(JSON.parse(result))
版权声明
本文为[Front Thoughts]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230551156530.html
边栏推荐
- Dry goods | how to extract thumbnails quickly?
- SystemVerilog(六)-变量
- 超分之TDAN
- 关于gcc输出typeid完整名的方法
- How to manually implement the mechanism of triggering garbage collection in node
- 122. The best time to buy and sell stocks II - one-time traversal
- 1217_使用SCons生成目标文件
- ECMAScript history
- 958. Complete binary tree test
- Client example analysis of easymodbustcp
猜你喜欢
PC电脑使用无线网卡连接上手机热点,为什么不能上网
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
102. Sequence traversal of binary tree
MySQL进阶之索引【分类,性能分析,使用,设计原则】
Leak detection and vacancy filling (6)
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
2021 Great Wall Cup WP
How to change input into text
958. Complete binary tree test
Matlab / Simulink simulation of double closed loop DC speed regulation system
随机推荐
高德地图搜索、拖拽 查询地址
Commonly used functions -- spineros:: and spineros::)
How to change input into text
386. 字典序排数(中等)-迭代-全排列
HCIP第五次实验
练习:求偶数和、阈值分割和求差( list 对象的两个基础小题)
Chrome浏览器的跨域设置----包含新老版本两种设置
470. Rand10() is implemented with rand7()
239. 滑动窗口最大值(困难)-单向队列、大顶堆-字节跳动高频题
122. 买卖股票的最佳时机 II-一次遍历
Using quartz under. Net core -- a simple trigger of [7] operation and trigger
2022制冷与空调设备运行操作判断题及答案
This point in JS
uni-app黑马优购项目学习记录(下)
Kubernetes service discovery monitoring endpoints
41. The first missing positive number
Qt 修改UI没有生效
flink 学习(十二)Allowed Lateness和 Side Output
Sword finger offer 03 Duplicate number in array
MySQL进阶之索引【分类,性能分析,使用,设计原则】