我如何在 ionic 3 中制作动态单选按钮和 altertctl 选项
how i can make dynamic radio button along with altertctl option in ionic 3
我想在 ionic 3 中动态设置 alertctl 和单选按钮
我该怎么做?
home.ts
presentAlert() {
let alert = this.alertCtrl.create({
title: 'Low battery',
inputs:[
{
name:'radio 1',
label:'test',
value:'test',
type:'radio'
},
{
label:'new',
type: 'radio',
value:'new',
}
],
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'OK',
handler: (data:string) => {
console.log('OK clicked: '+data );
}
}
]
});
alert.present();
}
Expected Result: with dynamic data in alertctrl with radio buttons
还有其他方法吗??在离子 3
如果你可以在
中传递下面的 JSON 字符串
this.alertCtrl.create({
"title": "something",
"message": "Select option ",
"inputs" : [
{
"type":"radio",
"label":"something1",
"value":"something1"
},
{
"type":"radio",
"label":"something2",
"value":"something2"
}],
"buttons" : [
{
"text": "Cancel",
"handler": "here go your handler function"
},
{
"text": "Search",
"handler": "here go your handler function"
}]}})
那么应该可以了。字符串应该基于条件有多少单选按钮什么名字等等你可以传递的每件事
我发现只是将那些方法与参数
分开
this.jsonData=[
{"id":1,"label":"saw","name":"Prithivi"},
{"id":2,"label":"saw1","name":"Abimanyu"},
{"id":3,"label":"saw2","name":"malliga"},
];
presentAlert() {
let alert = this.alertCtrl.create();
alert.setTitle("Low battery");
for(let i=0;i<this.jsonData.length;i++)
{
alert.addInput({type: 'radio', label: this.jsonData[i]['label'], value: this.jsonData[i]['name'], });
}
alert.addButton({text:'ok',handler: (data:string) => {
console.log('OK clicked: '+data );
}});
alert.present();
}
我想在 ionic 3 中动态设置 alertctl 和单选按钮
我该怎么做?
home.ts
presentAlert() {
let alert = this.alertCtrl.create({
title: 'Low battery',
inputs:[
{
name:'radio 1',
label:'test',
value:'test',
type:'radio'
},
{
label:'new',
type: 'radio',
value:'new',
}
],
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'OK',
handler: (data:string) => {
console.log('OK clicked: '+data );
}
}
]
});
alert.present();
}
Expected Result: with dynamic data in alertctrl with radio buttons
还有其他方法吗??在离子 3
如果你可以在
中传递下面的 JSON 字符串this.alertCtrl.create({
"title": "something",
"message": "Select option ",
"inputs" : [
{
"type":"radio",
"label":"something1",
"value":"something1"
},
{
"type":"radio",
"label":"something2",
"value":"something2"
}],
"buttons" : [
{
"text": "Cancel",
"handler": "here go your handler function"
},
{
"text": "Search",
"handler": "here go your handler function"
}]}})
那么应该可以了。字符串应该基于条件有多少单选按钮什么名字等等你可以传递的每件事
我发现只是将那些方法与参数
分开this.jsonData=[
{"id":1,"label":"saw","name":"Prithivi"},
{"id":2,"label":"saw1","name":"Abimanyu"},
{"id":3,"label":"saw2","name":"malliga"},
];
presentAlert() {
let alert = this.alertCtrl.create();
alert.setTitle("Low battery");
for(let i=0;i<this.jsonData.length;i++)
{
alert.addInput({type: 'radio', label: this.jsonData[i]['label'], value: this.jsonData[i]['name'], });
}
alert.addButton({text:'ok',handler: (data:string) => {
console.log('OK clicked: '+data );
}});
alert.present();
}