1
後端的API:
網址:http://www.sample.com/getAllPersons多個HTTP請求2
[
{
"name": "ABC",
"occupation": "Student",
"address_url": "http://www.sample.com/address/person=hgjgjgyyfhg"
},
{
"name": "ABC1",
"occupation": "Carpenter",
"address_url": "http://www.sample.com/address/person=fsdafdsa"
},
{
"name": "ABC2",
"occupation": "Developer"
},
{
"name": "ABC3",
"occupation": "Tester",
"address_url": "http://www.sample.com/address/person=sgdfsgd"
}
]
網址:http://www.sample.com/address/person=hash_value
{
"address": "XYZ",
"city": "Phoenix",
"state": "Arizona",
"pin code": "3243242"
}
需要的對象的陣列: -
{
"name": "ABC",
"occupation": "Student",
"address": "XYZ",
"city": "Phoenix",
"state": "Arizona",
"pin code": "3243242"
}
我需要在視圖中顯示名稱,occ以上述兩個api網址提供每個人的完整地址。 注意:每個人的地址可能不可用。
請建議這樣做異步使用HTTP服務和承諾的最佳方法/觀測量的角2
我的解決方案:
創建getAllPersons的http請求的承諾。
然後功能:
- 將響應保存在組件類變量中。
- 爲每個對象的address_url創建一個http promise的數組(如果存在的話)。
- 返回Promise.all([地址URL承諾數組])
在然後函數:
- 迭代響應逐一併將其添加到含組分類address_url 變量。
有沒有更好的辦法?還建議如果這是一個三方面的層次結構。