search
HomeWeChat AppletMini Program DevelopmentRelevant introduction to the three-level linkage of provinces and municipalities in the development of small program components

Relevant introduction to the three-level linkage of provinces and municipalities in the development of small program componentsRendering:

Relevant introduction to the three-level linkage of provinces and municipalities in the development of small program components

Relevant introduction to the three-level linkage of provinces and municipalities in the development of small program components##Source code

  • index.wxml

    ##
    <import></import>
    <template></template>
  • index.js

      var city = require("../../utils/city.js");
    Page({
        data: {},
        onLoad: function() {
            console.log(&#39;onLoad...&#39;);
            var that = this;
            city.init(that);
        }
    });
  • address-temp.wxml

    <?xml version="1.0" encoding="utf-8"?>
    
    <template name="addressPicker"> 
      <view style="display:flex;margin:0;height:100%;align-items: center;justify-content: center"> 
        <view style="width:100%;"> 
          <picker bindchange="bindProvinceChange" value="{{provinceIndex}}" range="{{province}}"> 
            <view style="text-align:center;padding:10rpx;font-size:0.8rem">{{province[provinceIndex]}}</view> 
          </picker> 
        </view>  
        <view style="width:100%;"> 
          <picker bindchange="bindCityChange" value="{{cityIndex}}" range="{{city}}"> 
            <view style="text-align:center;padding:10rpx;font-size:0.8rem">{{city[cityIndex]}}</view> 
          </picker> 
        </view>  
        <view style="width:100%;"> 
          <picker bindchange="bindDistrictChange" value="{{districtIndex}}" range="{{district}}"> 
            <view style="text-align:center;padding:10rpx;font-size:0.8rem">{{district[districtIndex]}}</view> 
          </picker> 
        </view> 
      </view>
    </template>
    ##city.js
  • var city = {
        province: [&#39;-请选择-&#39;, &#39;福建省&#39;],
        city: {
            &#39;-请选择-&#39;: [&#39;-请选择-&#39;],
            &#39;福建省&#39;: [&#39;福州市&#39;, &#39;厦门市&#39;, &#39;泉州市&#39;]
        },
        district: {
            &#39;-请选择-&#39;: [&#39;-请选择-&#39;],
            &#39;福州市&#39;: [&#39;鼓楼区&#39;, &#39;台江区&#39;],
            &#39;厦门市&#39;: [&#39;湖里区&#39;, &#39;集美区&#39;],
            &#39;泉州市&#39;: [&#39;晋江市&#39;, &#39;安溪县&#39;]
        },
        provinceIndex: 0,
        cityIndex: 0,
        districtIndex: 0,
        selectedProvince: &#39;-请选择-&#39;,
        selectedCity: &#39;-请选择-&#39;,
        selectedDistrct: &#39;-请选择-&#39;
    };
    function init(that) {
        that.setData({
            &#39;city&#39;: city
        });
        var bindProvinceChange = function(e) {
            var city = that.data.city;
            that.setData({
                &#39;city.provinceIndex&#39;: e.detail.value,
                &#39;city.selectedProvince&#39;: city.province[e.detail.value],
                &#39;city.selectedCity&#39;: city.city[city.province[e.detail.value]][0],
                &#39;city.selectedDistrct&#39;: city.district[city.city[city.province[e.detail.value]][0]][0],
                &#39;city.cityIndex&#39;: 0,
                &#39;city.districtIndex&#39;: 0
            });
        };
        var bindCityChange = function(e) {
            var city = that.data.city;
            that.setData({
                &#39;city.cityIndex&#39;: e.detail.value,
                &#39;city.selectedCity&#39;: city.city[city.selectedProvince][e.detail.value],
                &#39;city.districtIndex&#39;: 0,
                &#39;city.selectedDistrct&#39;: city.district[city.city[city.selectedProvince][e.detail.value]][0]
            });
        };
        var bindDistrictChange = function(e) {
            var city = that.data.city;
            that.setData({
                &#39;city.districtIndex&#39;: e.detail.value,
                &#39;city.selectedDistrct&#39;: city.district[city.selectedCity][e.detail.value]
            });
        };
        that[&#39;bindProvinceChange&#39;] = bindProvinceChange;
        that[&#39;bindCityChange&#39;] = bindCityChange;
        that[&#39;bindDistrictChange&#39;] = bindDistrictChange;
    }
    module.exports = {
        init: init
    }

The above is the detailed content of Relevant introduction to the three-level linkage of provinces and municipalities in the development of small program components. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),