首页 > 解决方案 > 未调用 Bootbox 回调函数

问题描述

我正在尝试在 Angular2 应用程序中使用 Bootbox。我有以下代码:

  bootbox.confirm({
      message: "Are you sure you want to complete this action?",
      buttons: {
          confirm: {label: 'Yes', className: 'btn-success'},
          cancel: {label: 'No', className: 'btn-danger'}
      },
      callback: function (result: any) {
          console.log('Response equals: ' + result);
      }
  });

确认框在调用时正确显示,当单击“是”或“否”按钮时,确认框会消失。但是,回调函数没有触发,因为我没有收到控制台消息。

这是我第一次尝试将 Bootbox 注入应用程序,所以我不确定为什么没有调用回调函数。

有任何想法吗?

标签: javascriptangularjsangular-ui-bootstrapbootbox

解决方案


您是否尝试过使用功能(结果)删除':任何'。

bootbox.confirm({
    message: "This is a confirm with custom button text and color! Do you like it?",
    buttons: {
        confirm: {
            label: 'Yes',
            className: 'btn-success'
        },
        cancel: {
            label: 'No',
            className: 'btn-danger'
        }
    },
    callback: function (result) {
        console.log('This was logged in the callback: ' + result);
    }
});

http://bootboxjs.com/examples.html#bb-confirm-dialog。回调只接受一个参数,即结果。


推荐阅读