【发布时间】:2019-11-16 13:21:48
【问题描述】:
我正在制作一个显示选项数组的选定文本的 Ionic 应用程序,我正在使用 ion-picker 组件(互联网上没有那么多文档),当我 console.log 值时一切正常索引的它在控制台中显示正确的值,我也在使用警报将所选值显示为消息的一部分,但是当我选择例如第一个值时,警报没有显示任何值,那么如果我选择第二个值警报显示第一个值,我不明白这是怎么回事,因为 console.log 具有正确的值。
这是我的两个功能。
async selectHora() {
const times: PickerOptions = {
cssClass: 'horasSelect',
buttons: [
{
text: 'Cancelar',
role: 'cancel',
cssClass: 'btnCancel'
},
{
text: 'Confirmar',
handler: (value) => {
value = this.horaSeleccionada;
console.log('confirmacion', this.horaSeleccionada);
this.confirmacion(value);
}
}
],
columns: [
{
name: 'Horas',
options: [
{text: '8:00 - 9:00', value: 1},
{text: '9:00 - 10:00', value: 2},
{text: '10:00 - 11:00', value: 3},
{text: '11:00 - 12:00', value: 4},
{text: '12:00 - 13:00', value: 5},
{text: '13:00 - 14:00', value: 6},
{text: '14:00 - 15:00', value: 7},
{text: '15:00 - 16:00', value: 8},
{text: '16:00 - 17:00', value: 9},
{text: '17:00 - 18:00', value: 10}
]
}
]
};
const picker = await this.picker.create(times);
picker.present();
picker.onDidDismiss().then(async data => {
const col = await picker.getColumn('Horas');
console.log('Esta es la columna ', col);
this.horaSeleccionada = col.options[col.selectedIndex].value;
console.log(this.horaSeleccionada);
// this.confirmacion();
});
}
async confirmacion(value) {
const alert = await this.alertCtrl.create({
header: 'Confirmación Pedido',
subHeader: 'Si desea cambiar la hora, seleccione cancelar',
message: 'Su pedido será entregado entre las ' + value,
buttons: [
{
text: 'OK',
handler: () => {
console.log('ok texto', this.horaSeleccionada);
// this.router.navigateByUrl('/orderfinished');
}
}
],
});
await alert.present();
}
【问题讨论】:
标签: angular ionic-framework ionic4