当前位置:网站首页>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
边栏推荐
- Router object, route object, declarative navigation, programmed navigation
- JS parsing and execution process
- The system cannot be started after AHCI is enabled
- 122. 买卖股票的最佳时机 II-一次遍历
- 高德地图搜索、拖拽 查询地址
- Halo 开源项目学习(二):实体类与数据表
- 470. Rand10() is implemented with rand7()
- 92. Reverse linked list II byte skipping high frequency question
- 386. 字典序排数(中等)-迭代-全排列
- 440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
猜你喜欢

92. Reverse linked list II byte skipping high frequency question

Element calculation distance and event object

SystemVerilog (VI) - variable

1217_ Generating target files using scons

Summary of common SQL statements

Double pointer advanced -- leetcode title -- container with the most water

102. 二叉树的层序遍历

470. Rand10() is implemented with rand7()

In embedded system, must the program code in flash be moved to ram to run?

92. 反转链表 II-字节跳动高频题
随机推荐
Learning record of uni app dark horse yougou project (Part 2)
Change Oracle to MySQL
Index: teach you index from zero basis to proficient use
Client example analysis of easymodbustcp
Collection of common SQL statements
常用SQL语句总结
122. The best time to buy and sell stocks II - one-time traversal
Websocket (basic)
MySQL进阶之索引【分类,性能分析,使用,设计原则】
1217_使用SCons生成目标文件
402. 移掉 K 位数字-贪心
Solution of Navicat connecting Oracle library is not loaded
In embedded system, must the program code in flash be moved to ram to run?
Hcip fifth experiment
2021 Great Wall Cup WP
1217_ Generating target files using scons
386. Dictionary order (medium) - iteration - full arrangement
圆环回原点问题-字节跳动高频题
Add drag and drop function to El dialog
198. Looting - Dynamic Planning