關閉。此問題不可重現或由拼寫錯誤引起。它目前不接受答案。
想改善這個問題嗎?更新問題,使其成為 Stack Overflow的主題。
17 小時前關閉。
改進這個問題我們如何從物件訪問某個屬性值?,我想從 regionAreaDto 訪問區域值。我試過 element.territoryAreaDto[0].area 但它不起作用
#Sample Object (items) - items 是一個物件陣列。
{
"id": 19,
"region": "37",
"repmid": 630,
"territoryAreaDto": [
{
"id": 3,
"regionId": 32,
"territoryAssignmentsId": 19,
"area": "121"
}
]
}
#代碼
public static modifyTerritoryAssignmentsObject(items: any) {
items.forEach(element => {
if(element.territoryAreaDto) {
console.log('element.territoryAreaDto.area;' , element.territoryAreaDto[0].area)
element.area = element.territoryAreaDto.area;
}
})
return items;
}
uj5u.com熱心網友回復:
試試這個。
"id": 19,
"region": "37",
"repmid": 630,
"territoryAreaDto": [
{
"id": 3,
"regionId": 32,
"territoryAssignmentsId": 19,
"area": "121"
}
]
}
public static modifyTerritoryAssignmentsObject(items: any) {
items.forEach(element => {
if(element.territoryAreaDto) {
console.log('element.territoryAreaDto.area;' , element.territoryAreaDto[0].area)
element.area = element.territoryAreaDto.map((res: any) => res.area);
}
})
return items;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/390675.html
標籤:javascript 有角的 打字稿
下一篇:避免以角度多次呼叫函式
