小程序选择门店后带参返回上一页

子页(需要选择的):

wxml:

<view class="box2" wx:for="{{store}}">
    <view class="box2_son1" data-id="{{index}}" bindtap="backIndex">
      <view class="box2_son1_left">{{item.store_name}}</view>
      <view class="box2_son1_right" wx:if="{{item.num == 1 }}">距您最近的门店</view>
      <view class="box2_son1_right" wx:else></view>
    </view>
  </view>
 

js:

 // 选择门店回上一页(首页)
  backIndex: function (e) {
    console.log('回首页!!!!')
    var me = this;
    let idindex = e.currentTarget.dataset.id;
    var stores = me.data.data.data;
    var dis = stores[idindex].dis
    var id = stores[idindex].id
    console.log(stores)
    console.log(idindex)
    console.log(dis)
    console.log(id)
    App._post_form('Storeinfo/sele', {id: id,km: dis}, result => {
      var touch_data = result.data.data;
      var touch_id = touch_data.id;
      var touch_store_name = touch_data.store_name;
      me.setData({
        touch_data: touch_data,
        touch_id: touch_id,
        touch_store_name: touch_store_name,
      })
      var pages = getCurrentPages();
      var prevPage = pages[pages.length - 2]; //上一个页面
        //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
      prevPage.setData({
        mydata: {
          touch_id: touch_id,
          touch_store_name: touch_store_name,
        }
      })
      wx.navigateBack({//返回
        delta: 1
      })
    }, false, () => {
      wx.hideLoading();
    });
  },

 

父页(需要选择后显示的):

wxml:

 <view class="here_name" wx:if="{{touch_store_name}}">{{touch_store_name}} ></view>
 <view class="here_name" wx:else>{{jingwei}} ></view>
 
js:
data: {
    mydata: [],
    touch_store_name: "",
}
 
在onShow里面写:
  // 接收门店页面传过来的值
  var pages = getCurrentPages();
  var currPage = pages[pages.length - 1]; //当前页面
  let json = currPage.data.mydata;
  let touch_store_name = json.touch_store_name;
  console.log(json)//为传过来的值
  console.log(touch_store_name)//为传过来的门店名
  _this.setData({
    touch_store_name: touch_store_name
  })

 

 

 

 

 

参考链接:https://www.cnblogs.com/ldlx-mars/p/10598708.html

posted @   宅女二二  阅读(44)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示