I learned a very interesting algorithm today
The interface data provided by the backend is an object, and there are multiple arrays in the object. However, you need to flatten these arrays, expand them and combine them into one large array. The analysis and writing at this time is as follows:
let a = {
name1:["a1","a2","a3"],
name2:["b1","b2","b3"],
name3:["c1","c2","c3"]
}
1. Use keys when you want to get its keys
Object.keys(a)
(3) ['name1', 'name2', 'name3']
2. Use values when you want to get its value.
Object.values(a)
(3) [Array(3), Array(3), Array(3)]
0
:
(3) ['a1', 'a2', 'a3']
1
:
(3) ['b1', 'b2', 'b3']
2
:
(3) ['c1', 'c2', 'c3']
length
:
3
[[Prototype]]
:
Array(0)
3. If you encounter the following
let a = {
name1:["a1"],
name2:["b1","b2"],
name3:["c1","c2","c3"]
}
Directly put together variable arrays
Object.values(a).flat()
(6) ['a1', 'b1', 'b2', 'c1', 'c2', 'c3']
Make a drop-down selection. The function can be searched or selected. When selected, only the person will be displayed.
1. Make a pop-up window. The pop-up window has a sponsoring unit and a sponsor.
2. When selecting the proposer, the unit will be displayed in another input box.
3. The proposer still needs to splice grandfather + father + son