小程序开发 绑定自定义数据data- 及JS获取

时间:2022-01-07 20:18:12
1wxml
<!-- 茶系显示隐藏函数sectionSelect -->
<view class="img-fur" data-id="{{item.id}}" bindtap="sectionSelect">
<image class="section-img" src="{{item.sectionurl}}"></image>
</view> 2js
sectionSelect:function(e){
// var that=this;
// console.log(e.currentTarget.dataset.id);
var idselect = e.currentTarget.dataset.id;
var teaamong = this.data.teaamong;
if (idselect==1){
// console.log(this.data.teaamong[id].teatitle)
for (var i = 0; i < teaamong.length;i++){
console.log(teaamong[i].listshow);
teaamong[i].listshow=true;
this.setData({
teaamong: teaamong,
});
}
} else {
for (var i = 0; i < teaamong.length;i++){
teaamong[i].listshow=false;
};
teaamong[idselect-2].listshow = true;
this.setData({
teaamong: teaamong,
});
}
},