[英]concatenate two objects containing arrays in to one array containing objects
我正在嘗試將包含對象的兩個數組連接到一個包含所有對象的數組中,我希望這是有意義的
getEntries() {
const linksArr = ['/api/aggregated', '/api/techmetro'];
axios.all(linksArr.map(l => axios.get(l))).then(axios.spread((...res) => {
// all requests are now complete
this.articles = res;
}));
},
我知道了
articles:Array[2]
0:Object
config:Object
data:Object
data:Array[10]
0: Object
...
meta:Object
headers:Object
request:XMLHttpRequest
status:200
statusText:"OK"
1:Object
config:Object
data:Object
data:Array[1]
0: Object
0:Object
meta:Object
headers:Object
request:XMLHttpRequest
status:200
statusText:"OK"
但我的目標是:
articles:Array[11]
0: Object
...
我想念什么? 非常感謝
我想你在找
….then(([aggregateds, techmetros]) => {
this.articles = aggreateds.concat(techmetros);
});
或同等學歷
….then(res => {
this.articles = res[0].concat(res[1]);
});
如果可以存在多個要串聯的數組(即res.length != 2
),則可以使用[].concat(...res)
。
我認為最簡單的方法是從響應中獲取數據,例如
... .then( allresponses =>
allresponses.reduce( (current, item) => current.concat( item.data ), []) ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.