How to realize the three-level linkage of ecshop address in WeChat Mini Programs
This article introduces the relevant knowledge of "how to achieve the three-level linkage of ecshop addresses in WeChat Mini Programs". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
How to realize the three-level linkage of ecshop address by WeChat Mini Programs
Picker tag, an official example:
Current selection of region selector: {{array [index]} Page ({data: {array: ['US', 'China', 'Brazil', 'Japan'], index: 0,}, bindPickerChange: function (e) {console.log ('picker send selection change, carry value is', e.detail.value) this.setData ({index: e.detail.value})},})
Wxml page:
Receiving address {{province [provinceIndex]}} {{city [cityIndex]}} {{district [districtIndex]}}
Js page:
Var app = getApp () Page ({data: {motto: 'jxcat', serverUrl: app.globalData.ajaxUrl, baseUrl: app.globalData.baseUrl, title: "ship to address", address_id: ", address:", province: [], province_id: [], / / the data returned by the backend corresponds to region_id city,district the same province_name: [], / / the data returned by the backend corresponds to region_name provinceIndex: 0 / / options selected on the wxml page Starting from 0, provinceId: 0, / / get the region_id city corresponding to province_id: [] according to the option selected on the wxml page. City_id: [], city_name: [], cityIndex: 0, cityId: 0, district: [], district_id: [], district_name: [], districtIndex: 0, districtId: 0,} OnLoad:function (options) {/ / Page initialization parameter var that = this var get_data wx.checkSession for page jump brought by options ({success: function () {/ / login state unexpired 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 item0 I