微信小程序,bindtap问题请柬

图片描述

现在的问题如上图,我想执行audioContrl只修改对应的view,但是现在一改,所有view的值都改了,我想应该是soundswitch我全部用的是一个,但是微信不让我用一下这种形式

soundswitch{{id}}="{{soundswitch}}"
<view wx:for="{{src}}" class="iconArea" bindtap="audioContrl" data-id="{{item.id}}" data-soundswitch="{{soundswitch}}">
      <view class="iconfont icon-{{item.icon}}"></view>
      <audio src="{{item.url}}" id="sound{{item.id}}" controls loop="true"></audio>
</view>
audioContrl: function (e) {
    var id = e.currentTarget.dataset.id;
    var soundSwitch = e.currentTarget.dataset.soundswitch+id;
    //console.log()
    wx.createAudioContext('sound' + id).play();
    this.setData({
      soundswitch: "no"
    })
  }

那么我要怎么才能每次修改的只是鼠标点击的事件的值呢?其他的不改

阅读 3.8k
2 个回答

加入index

<view wx:for="{{src}}" class="iconArea" bindtap="audioContrl" data-id="{{item.id}}" data-soundswitch="{{item.soundswitch}}" data-index="{{index}}">
      <view class="iconfont icon-{{item.icon}}"></view>
      <audio src="{{item.url}}" id="sound{{item.id}}" controls loop="true"></audio>
</view>
audioContrl: function (e) {
    var {id,index} = e.currentTarget.dataset;
    //console.log()
    wx.createAudioContext('sound' + id).play();
    this.setData({
      [`src[${index}].soundswitch`]: "no"
    })
  }

把播放列表写在一个数组里 判断传过来的id的值 通过id去修改相对应记录的播放状态属性值

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题