如何获取在 ionic 的日期时间组件中选择的用户值?
How do I get the user value selected in a date time component in ionic?
我正在使用 Ionic Framework 版本:3.1.1,我需要(基本上)双向数据绑定,但我无法弄清楚...我有这个:
在HTML:
<ion-datetime (click)="toggle()" [ngClass]="prod" displayFormat="D"
doneText="I want" cancelText="I don't"
[(ngModel)]="days" dayValues="0,1,2,3,4,5,6,7,8,9,10"
item-left>
</ion-datetime>
在 TS:
days = 0;
constructor(public navCtrl: NavController, public navParams: NavParams) { }
toggle(){
console.log(this.days);
}
但是当我在日期时间选择器中选择一天并单击 "I want" 按钮时,控制台中显示一个空字符串,有什么建议吗?提前致谢:)
最后,看了很多帖子和离子文档和组件后,我明白了 displayFormat="D"
是问题所在,它是无效的!因此,days
中没有分配任何内容。我尝试了几种方法来使用 Ionic 的 DateTime 组件实现数字选择器,但我意识到这不可能如我所愿,displayFormat
属性需要特定格式(如 here 所示)并且只是 D
不合适。
我用 Ion Multi Item Picker component 弄明白了。我的代码如下:
在HTML:
<ion-multi-picker [ngClass]="prod" doneText="I want" cancelText="I don't"
[(ngModel)] = "days" (ionChange)="toggle()"
placeholder=" " item-content item-left [multiPickerColumns]="quantityValues">
</ion-multi-picker>
在TS:
quantityValues = [];
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.quantityValues = [{
name: 'col1',
options: [
{ text: '0', value: '0' },
{ text: '1', value: '1' },
{ text: '2', value: '2' },
{ text: '3', value: '3' },
{ text: '4', value: '4' },
{ text: '5', value: '5' },
{ text: '6', value: '6' },
{ text: '7', value: '7' },
{ text: '8', value: '8' },
{ text: '9', value: '9' },
{ text: '10', value: '10' }
]
}];
}
toggle(){
console.log(this.days);
}
我希望这对进一步的问题有所帮助:)
我正在使用 Ionic Framework 版本:3.1.1,我需要(基本上)双向数据绑定,但我无法弄清楚...我有这个:
在HTML:
<ion-datetime (click)="toggle()" [ngClass]="prod" displayFormat="D"
doneText="I want" cancelText="I don't"
[(ngModel)]="days" dayValues="0,1,2,3,4,5,6,7,8,9,10"
item-left>
</ion-datetime>
在 TS:
days = 0;
constructor(public navCtrl: NavController, public navParams: NavParams) { }
toggle(){
console.log(this.days);
}
但是当我在日期时间选择器中选择一天并单击 "I want" 按钮时,控制台中显示一个空字符串,有什么建议吗?提前致谢:)
最后,看了很多帖子和离子文档和组件后,我明白了 displayFormat="D"
是问题所在,它是无效的!因此,days
中没有分配任何内容。我尝试了几种方法来使用 Ionic 的 DateTime 组件实现数字选择器,但我意识到这不可能如我所愿,displayFormat
属性需要特定格式(如 here 所示)并且只是 D
不合适。
我用 Ion Multi Item Picker component 弄明白了。我的代码如下:
在HTML:
<ion-multi-picker [ngClass]="prod" doneText="I want" cancelText="I don't"
[(ngModel)] = "days" (ionChange)="toggle()"
placeholder=" " item-content item-left [multiPickerColumns]="quantityValues">
</ion-multi-picker>
在TS:
quantityValues = [];
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.quantityValues = [{
name: 'col1',
options: [
{ text: '0', value: '0' },
{ text: '1', value: '1' },
{ text: '2', value: '2' },
{ text: '3', value: '3' },
{ text: '4', value: '4' },
{ text: '5', value: '5' },
{ text: '6', value: '6' },
{ text: '7', value: '7' },
{ text: '8', value: '8' },
{ text: '9', value: '9' },
{ text: '10', value: '10' }
]
}];
}
toggle(){
console.log(this.days);
}
我希望这对进一步的问题有所帮助:)