收货地址

address.js

selectAddress(event) {
    try {
      wx.setStorageSync('addressId', event.currentTarget.dataset.addressId);
      wx.setStorageSync('index', event.currentTarget.dataset.index);
    } catch (e) {
    }
    //选择该收货地址
    var addressList = this.data.addressList
    var index = event.currentTarget.dataset.index
    var str = addressList
    wx.navigateBack()
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1]; //当前页面
    var prevPage = pages[pages.length - 2]; //上一级页面
    // 直接调用上一级页面page对象,存储数据到上一级页面中
    prevPage.setData({
      checkedAddressList: str[index],
      state: 1
    })

  },
address.html

<view class="all" data-address-id="{{item.id}}" data-index="{{index}}"></view>


index.js
data:{
    checkedAddressList: {},
    state: 0,
    checkedAddress:{}
}
onShow: function () {
    // 页面显示
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1]; //当前页面
    console.log(currPage.data.checkedAddressList)
    console.log(currPage.data)
    let checkedAddressList = currPage.data.checkedAddressList
    let checkedAddress = this.data.checkedAddress
    if (currPage.data.state === 1) {
      this.setData({
        checkedAddress: 0
      })
    }
}
index.html
 <view class="address-content" bindtap="selectAddress" wx:if="{{checkedAddressList.id > 0}}"></view>

 


本文转载:CSDN博客