我有一個名為 Lines 的物件陣列。Lines陣列位于rows陣列內,而rows 陣列位于tabs陣列內。我想從 lines 陣列中獲取一些資料并將它們放入另一個名為colors的陣列中
陣列看起來像這樣----
"tabs": [{
"selectedHouseType": "1",
"rows": [{
"selectedDecor": "2",
"lines": [{
"selectedColor": "white",
"selectedQty": 0,
"selectedUnit": "1",
}, {
"selectedColor": "black",
"selectedQty": "2",
"selectedUnit": "3",
}]
}, {
"selectedDecor": "1",
"lines": [{
"selectedColor": "black",
"selectedQty": 0,
"selectedUnit": "2",
"
}]
}]
}, {
"selectedHouseType": "select",
"rows": [{
"selectedDecor": "2",
"lines": [{
"selectedColor": "red",
"selectedQty": 0,
"selectedUnit": "",
}]
}]
}]
我想從lines陣列中收集資料并將它們放在另一個名為“ colors ”的陣列中
看起來像這樣---
colors: [{
"selectedColor": "white",
"selectedQty": 0,
"selectedUnit": "1",
}, {
"selectedColor": "black",
"selectedQty": "2",
"selectedUnit": "3",
},
{
"selectedColor": "black",
"selectedQty": 0,
"selectedUnit": "2",
},
{
"selectedColor": "red",
"selectedQty": 0,
"selectedUnit": "",
}
]
我正在使用vue js。我該怎么做呢?
uj5u.com熱心網友回復:
嘗試這個 :
const colors = tabs.reduce((acc, tab) => {
const rows = tab.rows
const lines = rows.reduce((acc, row) => {
const lines = row.lines
return [...acc, ...lines]
}, [])
return [...acc, ...lines]
}, [])
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/533660.html
上一篇:在拋出'std::length_error'what():basic_string::_M_create實體后終止呼叫
