Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何在ionic 3中创建动态单选按钮和altertctl选项_Angular_Ionic Framework_Ionic3_Radio Button - Fatal编程技术网

Angular 如何在ionic 3中创建动态单选按钮和altertctl选项

Angular 如何在ionic 3中创建动态单选按钮和altertctl选项,angular,ionic-framework,ionic3,radio-button,Angular,Ionic Framework,Ionic3,Radio Button,我想在ionic 3中动态设置alertctl和单选按钮 我怎么能做到 home.ts presentAlert() { let alert = this.alertCtrl.create({ title: 'Low battery', inputs:[ { name:'radio 1', label:'test', value:'test', type:'radio' },

我想在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();

}
预期结果:在alertctrl中使用单选按钮显示动态数据


还有其他方法吗??在ionic 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();

  }
this.jsonData=[
{“id”:1,“label”:“saw”,“name”:“Prithivi”},
{“id”:2,“标签”:“saw1”,“名称”:“Abimanyu”},
{“id”:3,“标签”:“saw2”,“名称”:“malliga”},
];
presentAlert(){
让alert=this.alertCtrl.create();
警报。设置标题(“电池电量不足”);
for(设i=0;i{
log('单击确定:'+数据);
}});
alert.present();
}

查看create()方法的参数,如果您可以看到json格式,那么您就知道该做什么了,我没有得到,请提供任何示例。。