服务器返回输入如下:
{"index":"1","face":"../images/a.png","name":"张三","age":"18"}
JS 代码如下:
Page({
data: {
ulist:[]
},
onLoad: function () {
var that = this
var utoken = wx.getStorageSync("utoken")
wx.request({
url: 'https://qq.com/WX/userlist.php',
data: {
utoken: utoken
},
success: function (res) {
that.setData({
ulist: res.data
})
}
})
},
Play:function(e){
var that=this
var ind = e.currentTarget.dataset.id
var voc = that.data.ulist[ind-1].face
console.log(voc)
}
})
Wxml代码如下:
<view class="xslist">
<block wx:for="{{ulist}}" wx:key="name">
<template is="userlista" data="{{item}}" />
</block>
</view>
<template name="userlista">
<view class="list-text">{{item.name}} </view>
<view class="list-text">{{item.age}} </view>
<view class="list-youimg">
<image data-id="{{item.index}}" class="list-img" src="{{item.face}}" bindtap="Play"></image>
</view>
</template>
问题是,在Play事件中,如何更改image中的图片?
网友回复:
var list = this .data.ulist // 修改第一个图片 list[0].image = './new-image.jpg' this .setData({ulist: list}) |
完美!非常感谢!