【短文】for循环生成的button添加不同的事件,点击按钮后改变按钮名字
发布于 4 年前 作者 hanchao 3979 次浏览 来自 分享

wxml

<view wx:for="{{result_list}}" wx:key=“key” wx:for-item=“result” data-id=“index”>

<button id = "{{index}}" class="cu-btn round bg-blue" bindtap="collect_button">{{result.collect}}</button>

</view>

js

collect_button:function(e){

var result_list = this.data.result_list

var that = this

var id = e.currentTarget.id

for (var i = 0; i < result_list.length;i++){

if(id == i){

	result\_list\[i\]\['collect'\] = '已收藏'

	wx.showToast({

	title: '收藏成功',

	duration:750

})

console.log(result\_list\[i\])

that.setData({

	result\_list:result\_list

})

}

}

},

回到顶部