1.
小程序多商品评论,循环图片上传组件和星星评分组件,处理方式:
页面加载时声明一个对象里面包含所以参数
例子:
for (var i = 0; i < that.data.goods1.length; i++) {
var temp = {
commentsContents: '',
commodityScore: 5,
commentsImagePath: '',
goodsId: this.data.goods1[i].goodsId,
creatorId: userId,
additionalEvaluation: 0,
logisticsScore:5,
serviceScore:5
};
this.data.com.push(temp);
}
在事件处理时赋值
例子:
id是下标值
this.data.com[id].commentsImagePath = e.detail.name.join(',');
2.接口返回值包含数组对象里面的图片地址。用逗号分隔的字符串的方式
怎么循环获取图片再渲染:重新生成一个对象并赋值
例子:
for (let i in res.data.commentslist) {
var img = res.data.commentslist[i].commentsImagePath
if (img == "" || img == null) {
console.log('111')
res.data.commentslist[i].ImagePath = [];
} else {
console.log('222')
console.log(img.split(','))
res.data.commentslist[i].ImagePath = img.split(',');
}
}
that.setData({
leng: res.data.commentslist.length,
comment1: res.data.commentslist
})