【问题标题】:ionic 3 - How to add a 'dont ask me again' checkbox to an alert controller?ionic 3 - 如何向警报控制器添加“不要再问我”复选框?
【发布时间】:2017-06-12 08:13:35
【问题描述】:

我正在使用 ionic3 并想在警报中添加一个“不要再问我”复选框。正如您在下面看到的,我的警报有三个选项:

1.保存并继续

2.继续不保存

3.取消

当用户点击复选框时,只有选项“保存并继续”应该被启用,其余的被禁用。

问题是我找不到一种方法来捕获 checkbox 点击事件来做到这一点。 有任何想法吗? 我使用警报控制器而不是 html 构建警报。

【问题讨论】:

  • "当用户点击复选框时,只有一个选项应该被启用,其余的被禁用" ... 什么选项?警报中的选项,表单中的选项?这个问题很难理解
  • 我编辑了这个问题。希望现在更清楚了。

标签: typescript checkbox alert ionic3


【解决方案1】:

警报控制器有一个名为 inputs 的选项:

 this
  .alert
  .create({
    title: 'Warning',
    inputs: [
      {
        type: 'checkbox',
        label: 'don\'t ask me again',
        handler:(e)=>{
          // e.checked is the checkbox value (true or false)
           console.info('value: ',e.checked)
        }
      }
    ],
    buttons: [
      {
        text: 'save and continue',
        handler: () => {
          //Do save stuff
        }
      },
       {
        text: 'continue without saving',
        handler: () => {
          //Do continue without saving stuff
        }
      },{text:'cancel'}
    ]
  }).present()

【讨论】:

  • 不错的解决方案。小问题是“不要再问我”中的撇号需要转义。 (编辑太小,我不能在这里自己修复)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-31
  • 2018-11-03
  • 2017-01-06
  • 2012-04-03
  • 2010-11-05
  • 2012-08-20
  • 2019-09-05
相关资源
最近更新 更多