let members=[{id:3, seal:'XXXXX', name:'Test'}, {}, {}]axios.get("xxx" + seal + "/xx") .then(response => { this.articleStream = this.members.forEach(item => { response.data.map(i => (i.user_id = item.id)); });})在 axios 调用中,articleStream 数组需要检查在axios 调用期间发送的user_idwith idinmembers数组,并将from映射到. 但目前它没有发送正确的数组。sealnamemembersarticleStream从 axios 调用返回的数组如下所示:[{ id: 5, user_id: 3},{}]
2 回答
繁星coding
TA贡献1797条经验 获得超4个赞
let members=[{id:3, seal:'XXXXX', name:'Test'}, {}, {}]
axios.get("xxx" + seal + "/xx")
.then(response => {
this.articleStream = this.members.forEach(item => {
response.data.map(i => {
if (i.user_id === item.id)) i.name = item.name;
};
});
})
侃侃无极
TA贡献2051条经验 获得超10个赞
如果我正确理解了您的问题,您正在寻找这样的东西:
axios.get("xxx" + seal + "/xx")
.then(response => {
this.articleStream = this.members.forEach(item => {
response.data.map(i => {
if(i.user_id == item.id){
return [...i, item.name]
}
});
});
})
这将在用户 ID 和文章用户 ID 匹配的每篇文章上添加用户名
如果要合并数组之间的所有数据,请更改以下内容:return [...i, item.name] 在 return [...i, ...item] 上面的示例中
添加回答
举报
0/150
提交
取消