【问题标题】:Sweet alert no works with cancel button甜蜜警报不适用于取消按钮
【发布时间】:2015-04-24 09:07:44
【问题描述】:

我正在使用甜蜜警报库,但取消按钮有问题。这是我的甜蜜警报代码:

sweetAlert({
        title: title,
        text: text + ' ' + courseList,
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: confirmButtonText,
        cancelButtonText: "Continue with purchase",
        closeOnConfirm: false,
        closeOnCancel: false,
        html: true
    },
    function(isConfirm) {
        if (isConfirm) {
            angular.forEach(repeatedCourses, function(repeatedCourse) {
                $rootScope.$apply(function() {
                    this.removeCoursePurchase(repeatedCourse);
                }.bind(this));
            }.bind(this));
            $rootScope.$broadcast('uncheckCheckboxes');
            swal("Deleted!", "Your purchase has been refreshed.", "success");
        } else {
            swal("Cancelled", "Your imaginary file is safe :)", "error");
        }
    }.bind(this));

当用户点击确认按钮时,工作正常,但如果点击取消按钮没有任何作用,它不会出现“取消”框,我不知道为什么!

【问题讨论】:

  • @RGraham 函数 sweetAlert 的缩写
  • 您是否在else 语句上设置了断点?会被击中吗?
  • 是的,当用户点击取消按钮时它不会进入function(isConfirm){},但点击接受时它会进入。 @RGraham
  • @Crisiiii 你解决了吗?

标签: javascript angularjs bind sweetalert


【解决方案1】:

去掉附加到回调函数的.bind(this),它就可以工作了。

【讨论】:

  • 是的,但这会破坏其他功能。什么实际的解决方案可以确保两者都有效?
  • 不要绑定到 this,而是使用 var _self = this;而是
猜你喜欢
  • 1970-01-01
  • 2022-11-13
  • 1970-01-01
  • 2021-10-22
  • 2023-03-20
  • 2018-09-29
  • 1970-01-01
  • 2018-07-25
相关资源
最近更新 更多