Framework7 更改前确认切换

Framework7 Toggle with confirmation before change

我想用 Framework7 创建一个开关,用户应该在开关关闭之前确认(并且只有在关闭时,而不是在打开时 - 也许这是相关的)。我的切换是这样创建的:

var toggle = app.toggle.create({
  el: '#myToggle',
  on: {
    change: function() {
      if (toggle.checked) {
        // let user confirm to uncheck toggle before
      } else {
        // check toggle and do something
      }
    }
  }
});

感谢任何帮助:)

由于无法向切换添加确认,我刚刚创建了两个看起来有点像切换的分段按钮:

<div class="list no-hairlines">
  <ul>
    <li class="item-content">
      <div class="item-inner">
        <div class="item-title">My Toggle</div>
        <div class="segmented segmented-strong toggle-buttons">
          <button id="btn-toggle-off" class="button button-small">off</button>
          <button id="btn-toggle-on" class="button button-small button-active">on</button>
          <span class="segmented-highlight"></span>
        </div>
      </div>
    </li>
  </ul>
</div>

然后在点击事件中我只是调用了一个确认:

$$('#btn-toggle-off').on('click', function(evt) {
  app.dialog.confirm(text, title, callbackOk, callbackCancel);
}

callbackOk 中,我将按钮切换为活动 class:

$$('#btn-toggle-off').addClass('button-active');
$$('#btn-toggle-on').removeClass('button-active');