对象型数组添加字段?
let arr = [{id:1,name:"张三",num:10},{id:2,name:"李四",num:5},{id:3,name:"王二",num:8},{id:4,name:"麻子",num:6}]
arr.map(item=>{
item.price = ""
wx.request({
url:"接口",
success(res){
item.price = res.data.data.price
}
})
})
console.log(arr) //[{id:1,name:"张三",num:10,price:5},{id:2,name:"李四",num:5,price:8},{id:3,name:"王二",num:8,price:10},{id:4,name:"麻子",num:6,price:10}]
<view wx:for="{{arr}}" wx:key="index">
<view>{{item.num}}</view>
<view>{{item.price}}</view>
</view>
//只显示name,并没有price
4 回复