当前位置:网站首页>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
边栏推荐
- In ancient Egypt and Greece, what base system was used in mathematics
- 一些问题一些问题一些问题一些问题
- Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
- Arithmetic expression
- 【Appium】通过设计关键字驱动文件来编写脚本
- 122. 买卖股票的最佳时机 II-一次遍历
- 嵌入式系统中,FLASH中的程序代码必须搬到RAM中运行吗?
- Using quartz under. Net core - calendar of [6] jobs and triggers
- For the space occupation of the software, please refer to the installation directory
- 470. 用 Rand7() 实现 Rand10()
猜你喜欢

Leak detection and vacancy filling (6)

2022年茶艺师(初级)考试模拟100题及模拟考试

JVM class loading mechanism

440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题

编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)
![[difference between Oracle and MySQL]](/img/90/6d030a35692fa27f1a7c63985af06f.png)
[difference between Oracle and MySQL]

102. 二叉树的层序遍历

土地覆盖/利用数据产品下载

102. Sequence traversal of binary tree
![Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers](/img/65/89473397da4217201eeee85aef3c10.png)
Using quartz under. Net core -- general properties and priority of triggers for [5] jobs and triggers
随机推荐
394. String decoding - auxiliary stack
ECMAScript history
2021 Great Wall Cup WP
How to manually implement the mechanism of triggering garbage collection in node
Type judgment in [untitled] JS
Compare the performance of query based on the number of paging data that meet the query conditions
Write a regular
索引:手把手教你索引从零基础到精通使用
1217_使用SCons生成目标文件
Generating access keys using JSON webtoken
Future usage details
uni-app黑马优购项目学习记录(下)
Sword finger offer 22 The penultimate node in the linked list - speed pointer
Some questions some questions some questions some questions
2021长城杯WP
Client example analysis of easymodbustcp
Kubernetes 服务发现 监控Endpoints
31. Next arrangement
STM32 entry development board choose wildfire or punctual atom?
HCIP第五次实验