鍍金池/ 問答/HTML/ 微信小程序,多個view綁定相同點擊事件,如何綁定當前view

微信小程序,多個view綁定相同點擊事件,如何綁定當前view

clipboard.png

clipboard.png

如圖所示兩個欄目分別彈出不同的的從底部彈出的彈層 怎么定位當前的view對應的彈層呢

<view class='item'>
<view bindtap="showModal">已選擇</view>
<view class="mask" bindtap="hideModal" wx:if="{{ModalStatus}}"></view>
<view animation="{{animationData}}" class="commodity_attr_box" wx:if="{{ModalStatus}}">
  <view class='product_info box-center-v border'>規(guī)格彈出層</view>
</view>
</view>
<view class='item'>
<view bindtap="showModal">配送至</view>
<view class="mask" bindtap="hideModal" wx:if="{{ModalStatus}}"></view>
<view animation="{{animationData}}" class="commodity_attr_box" wx:if="{{ModalStatus}}">
  <view class='product_info box-center-v border'>地址彈出層</view>
</view>
</view>
showModal: function () {
    // 顯示遮罩層
    var animation = wx.createAnimation({
      duration:300,
      timingFunction: "ease",
      delay: 0,
    })
    this.animation = animation
    animation.translateY(600).step()
    this.setData({
      animationData: animation.export(),
      ModalStatus: true
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)
  },
  //隱藏對話框
  hideModal: function () {
    // 隱藏遮罩層
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(400).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        ModalStatus: false
      })
    }.bind(this), 200)
  }
回答
編輯回答
萌面人

你是想知道現在彈起的是哪個view嗎?那你為何不設個變量,存當前彈窗的隊列,最后一個就永遠是最上面的,多彈窗設計下的管理方案。

2017年6月24日 23:27
編輯回答
悶騷型

可以傳個值給點擊事件:

<view class="mask" data-index='one' bindtap="hideModal" wx:if="{{ModalStatus}}"></view>


hideModal:(e)=>{
    let index=e.datail.index;
    ///dome somethings... 
}
2017年2月2日 15:32