【问题标题】:Bootbox callback function not being called未调用 Bootbox 回调函数
【发布时间】:2018-09-17 15:25:36
【问题描述】:

我正在尝试在 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 注入应用程序,所以我不确定为什么没有调用回调函数。

有什么想法吗?

【问题讨论】:

    标签: javascript angularjs angular-ui-bootstrap bootbox


    【解决方案1】:

    您是否尝试过使用 function(result) remove ':any'。

    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。回调只接受一个参数,即结果。

    【讨论】:

    • 是的,我也尝试过这种方式,但它也不起作用。我仍然看到相同的行为......除了回调函数触发之外,一切都按预期工作。
    • try bootbox.confirm("这是默认确认!", function(result){ console.log('This was logged in the callback: ' + result); });基本的例子。如果不调用这种方式回调,那么问题不在于回调。其他一些操作可能会阻止它调用回调。
    • 我能够解决这个问题,这实际上是由我在打字稿文件中调用方法的方式引起的。我仍然面临以下问题:我试图在回调中调用我的打字稿文件中的另一个函数,我得到一个未定义的函数错误回调:函数(结果){this.sendMessage(类型,响应);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 2016-10-20
    • 1970-01-01
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多