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
添加之后setData了吗?
https://developers.weixin.qq.com/s/6HnNKBmy7FkQ 代码片段
map是返回一个新数组 你应该 let arr1 = arr.map(item=>去承接。打印arr1,且setData
//修改数组中对象的值 var printPrice = "item["+i+"].print_price"; this.setData({ [printPrice]: e.detail.value }); //修改对象中的属性值 this.setData({ ['aa.a']: 3 }) console.log(this.data.aa.a); //3 //修改普通data值 this.setData({ currentValue: "bbb" })
['v.name']: 3
})
还是不行
this.setData({
[printPrice]: e.detail.value
});
这样能看懂吗
var shopName = "item["+i+"].name"
http.request("接口").then(resp=>{
that.setData({
[shopName]: 3
})
console.log(resp.data.data)
})
})
that.setData({
list:res.data.content
})