我正在使用 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);
}
但是当我在日期时间选择器中选择一天并单击“我想要”按钮时,控制台中会显示一个空字符串,有什么建议吗?提前致谢 :)
最后,在阅读了很多帖子并阅读了 ionic 文档和组件后,我可以理解displayFormat="D"
是问题所在,无效!因此,在 中没有分配任何内容days
。我试过多种方法来实现像使用离子的日期时间组成了一些选择器,但我意识到,这是不可能的,因为我想要的displayFormat
属性需要特定的格式(因为它显示出在这里),只是D
不正确的。
我使用Ion Multi Item Picker 组件找到了它。我的代码如下:
在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);
}
我希望这有助于进一步的问题:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句