【问题标题】:Ionic 2/3 How to access values in a Radio AlertIonic 2/3 如何访问 Radio Alert 中的值
【发布时间】:2017-08-28 19:28:27
【问题描述】:

我正在使用带有 Ionic 3 的 JavaScript 并在 iOS 上工作。我正在尝试实现一个带有 Radio 选项的警报供用户选择。

我无法在以下代码中使用/访问警报中选定的 Radio 值:

   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();

【问题讨论】:

    标签: javascript ionic-framework ionic2 alert ionic3


    【解决方案1】:

    您可以在 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);
            }
        }
    ]
    

    【讨论】:

      【解决方案2】:

      您确实在处理程序中获得了无线电数据。检查the docs..您的 Ok 处理程序会将数据作为参数。

          buttons: [
            {
              text: 'Cancel',
              role: 'cancel',
              handler: () => {
                console.log('Cancel clicked');
              }
            },
            {
              text: 'OK',
              handler: (radiobuttonData) => {
                console.log('OK clicked: '+ radiobuttonData );//here
              }
            }
          ]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-25
        • 2016-02-21
        • 2018-08-10
        • 2017-12-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多