![](/img/trans.png)
[英]What is the TypeScript type of an array of different Angular components?
[英]how to combine 2 different array lists [Angular,typescript]
我有 2 個 arraylist 如下所示,我必須組合數組以獲取新數組列表中的所有值,其中 uuid 在兩個列表中都是通用的,最終列表應該包含與兩者中的 UUID 關聯的所有值arraylist
清單 1:
[
{
"uuid":"01",
"plan" : "aaaa",
"other_details":"xxxxxx"
},
{
"uuid" : "02",
"plan" : "bbbb",
"other_details":"yyyyyyy"
},
{
"uuid" : "03",
"plan" : "cccc",
"other_details":"zzzzzz"
},
{
"uuid" : "04",
"plan" : "dddd",
"other_details":"uuuuuu"
}
]
清單 2:
[
{
"uuid":"01",
"office" : "India",
"status":"running"
},
{
"uuid" : "02",
"office" : "USA",
"status":"running"
},
{
"uuid" : "03",
"office" : "Germany",
"status":"running"
},
{
"uuid" : "04",
"office" : "Australia",
"status":"shutdown"
}
]
我必須將 2 個數組列表與唯一的“UUID”結合起來,數組應該看起來像
[
{
"uuid":"01",
"plan" : "aaaa",
"other_details":"xxxxxx",
"office" : "India",
"status":"running"
},
{
"uuid" : "02",
"plan" : "bbbb",
"other_details":"yyyyyyy",
"office" : "USA",
"status":"running"
},
{
"uuid" : "03",
"plan" : "cccc",
"other_details":"zzzzzz",
"office" : "Germany",
"status":"running"
},
{
"uuid" : "04",
"plan" : "dddd",
"other_details":"uuuuuu",
"office" : "Australia",
"status":"shutdown"
}
]
我可以如下迭代數組嗎?
for(listItem1 in arraylist1){ //assuming I am storing the arraylist in variable arraylist1
for (listitem2 in arraylist2){
if(listItem1.uuid=== listItem2.uuid){
listItem = "" //assign values
}
}
}
如何創建第三個數組列表並將項目存儲在 arraylist 中
嘗試這個; 使用 ECMAScript 的擴展運算符來簡化它。
const mergedList = listOne.map(listItem1 => ({...listItem1, ...listTwo.find(listItem2 => listItem2.id === listItem1.id)}))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.