【Ionic3】ion-multi-picker placeholder

本文介绍如何在Ionic框架中使用ion-multi-picker组件,并设置其默认值及更改按钮文本为中文的方法。通过定义高度选择选项并利用placeholder属性,实现显示默认值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How to set ion-multi-picker's default value ? Using placeholder. Here is what I do. 
html :
  <button ion-item>
    <ion-label>Height</ion-label>
    <ion-multi-picker class="userHeight" placeholder='{{defaultHeight}}' item-content [multiPickerColumns]="heightChoose" [showReset]="true"></ion-multi-picker>
  </button>
ts :
export class PersonalInfoPage {
  // Height:
  defaultHeight:string; //default value
  heightChoose:any[];  //users can choose from options
  
  constructor(public navCtrl: NavController, public navParams: NavParams) {
    this.heightChoose = [
      {
        options: [
          { text: '100', value: '1' },
          { text: '101', value: '2' },
          { text: '102', value: '3' },
          { text: '103', value: '4' },
          { text: '104', value: '5' },
          { text: '105', value: '6' },
          { text: '106', value: '7' },
          { text: '107', value: '8' },
          { text: '108', value: '9' },
          { text: '109', value: '10' }],
      },
      {
        options: [{ text: 'cm', value: '1'}],
      }
    ];         
  }                                                                                                                         
  ionViewDidLoad() {
    console.log('ionViewDidLoad PersonalInfoPage');
    this.defaultHeight='160cm';
  }
}
Let's see the picture.




If you want to change "CANCEL" , " RESET" , " DONE" into Chinese , you can do in this way . 
    <ion-multi-picker class="userHeight" placeholder='{{defaultHeight}}' item-content [cancelText]="'取消'" [doneText]="'完成'" [resetText]="'重置'" [multiPickerColumns]="heightChoose" [showReset]="true"></ion-multi-picker>


Thanks for your reading.



评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值