ionic3使用ion-multi-picker插件实现省市区三级联动的城市选择

首先安装ion-multi-picker插件

输入命令:npm install ion-multi-picker --save

在app.module.ts中引入插件

import { MultiPickerModule } from 'ion-multi-picker';

@NgModule({
imports: [
  …………
  MultiPickerModule,
  …………
],
})

在某个页面使用时引入ion-multi-picker

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { EceiingPage } from './eceiing';
import {MultiPickerModule} from 'ion-multi-picker';

@NgModule({
  declarations: [
    EceiingPage,
  ],
  imports: [
    MultiPickerModule,
    IonicPageModule.forChild(EceiingPage),
  ],
})
export class EceiingPageModule {}


//EceiingPage页面中引入插件

在eceiing.html页面中调用插件


      

 eceiing.ts中定义变量dependentColumns

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,AlertController } from 'ionic-angular';
/**
 * Generated class for the EceiingPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-eceiing',
  templateUrl: 'eceiing.html',
})
export class EceiingPage {
 
  public dependentColumns:any;
  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              public alertCtrl: AlertController,

  ){
    this.dependentColumns=太长了,没有复制
 
  ionViewDidEnter(){
   
  }
  
}

省市区json的下载地址:https://raw.githubusercontent.com/raychenfj/ion-multi-picker/master/example/src/assets/chinese-cities.json

这样就可以实现三级联动城市的选择了

ionic3使用ion-multi-picker插件实现省市区三级联动的城市选择_第1张图片

 

你可能感兴趣的:(ionic3)