Javascript Ionic 2/3如何访问无线电警报中的值
我正在将JavaScript与Ionic 3一起使用,并在iOS上工作。我正在尝试实现一个带有无线电选项的警报,供用户选择 我无法在以下代码的警报中使用/访问选定的无线电值:Javascript Ionic 2/3如何访问无线电警报中的值,javascript,ionic-framework,ionic2,alert,ionic3,Javascript,Ionic Framework,Ionic2,Alert,Ionic3,我正在将JavaScript与Ionic 3一起使用,并在iOS上工作。我正在尝试实现一个带有无线电选项的警报,供用户选择 我无法在以下代码的警报中使用/访问选定的无线电值: let alert = this.alertCtrl.create({ title: 'Specify the reason', inputs: [ { type: 'radio', label: 'label 1',
let alert = this.alertCtrl.create({
title: 'Specify the reason',
inputs: [
{
type: 'radio',
label: 'label 1',
value: '0'
},
{
type: 'radio',
label: 'label 2',
value: '1'
}
],
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'OK',
handler: () => {
console.log('OK clicked: ' );
// I NEED TO GET THE VALUE OF THE SELECTED RADIO BUTTON HERE
}
}
]
});
alert.present();
您可以访问OK处理程序中的数据:
inputs: [
{
name: "myValue", // add a name property
type: 'radio',
label: 'label 1',
value: '0'
},
{
name: "myValue", // and here
type: 'radio',
label: 'label 2',
value: '1',
}
],
buttons: [
{
text: 'OK',
handler: data => {
console.log('OK clicked: ');
// access through 'data.[nameproperty]'
console.log(data.myValue);
}
}
]
你可以在你的处理器中获取无线电数据。检查..您的Ok处理程序将数据作为参数
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'OK',
handler: (radiobuttonData) => {
console.log('OK clicked: '+ radiobuttonData );//here
}
}
]