微信小程序 ecshop地址3级联动实现实例代码
picker标签,官方给出的实例:
Page({ data: { array: ['美国', '中国', '巴西', '日本'], index: 0, }, bindPickerChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ index: e.detail.value }) }, }) 地区选择器 当前选择:{{array[index]}}
wxml页面:
收货地址 {{province[provinceIndex]}} {{city[cityIndex]}} {{district[districtIndex]}}
js页面:
var app = getApp() Page({ data:{ motto: 'jxcat', serverUrl: app.globalData.ajaxUrl, baseUrl: app.globalData.baseUrl, title: "收货地址", address_id: "", address: "", province:[], province_id: [], //后台返回的数据对应 region_id city,district 与此相同 province_name: [], //后台返回的数据对应 region_name provinceIndex: 0, //wxml页面选择的选项,从0开始 provinceId: 0, //根据wxml页面选择的选项获取到province_id: []对应的region_id city:[]. city_id: [], city_name: [], cityIndex: 0, cityId: 0, district:[], district_id: [], district_name: [], districtIndex: 0, districtId: 0, }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 var that = this var get_data wx.checkSession({ success: function(){ //登录态未过期 wx.getStorage({ key: 'wcx_session', success: function(sres) { get_data = { m: 'api', c: 'user' , a: 'edit_address', wcx_session: sres.data, } if(options.act == 'edit'){ get_data = { m: 'api', c: 'user' , a: 'edit_address', id: options.id, wcx_session: sres.data, } } wx.request({ url: app.globalData.ajaxUrl, data: get_data, header: { 'content-type': 'application/json' }, success: function(res) { if(options.act == "edit"){ that.data.provinceId = res.data.consignee.province that.data.cityId = res.data.consignee.city that.data.districtid = res.data.consignee.district } for(var i=0; i
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!