【问题标题】:Item deleted is shown even after the deletion即使在删除之后也会显示已删除的项目
【发布时间】:2019-09-09 09:08:35
【问题描述】:

我使用sweetalert 2进行删除,但是当我点击删除图标时,会出现sweetalert,当我在一个项目中确认删除时,它不会删除,但之后,我下次点击删除图标时相同的项目被删除,然后出现sweetalert。
附:第一次从数组中删除项目

$scope.remove = function (i) {
    // let r = confirm("Are you sure? Do you need to delete the keyword?");
    //  let r = false;
    swal({
        title: "Are you sure?",
        text: "Once aaa deleted, you will not be able to recover this imaginary file!",
        icon: "warning",
        buttons: true,
        dangerMode: true,
        showLoaderOnConfirm: true
    })
    .then((willDelete) => {
        if (willDelete) {
            // console.log("r2success" + r);
            // console.log("r1success" + r);
            // r = true;
            $scope.taggingRows.splice(i, 1);
            // console.log(" i " + i + " & " + "r " + r);
            $scope.taggingRowsAct.splice(i, 0);
            swal("Your file has been deleted!", {
                icon: "success",
            })

        } else {
            swal("Your file was not deleted!");
            console.log("r1canceled" + r);
            r = false;
            console.log("r2canceled" + r);
        }
    });

【问题讨论】:

    标签: angularjs sweetalert2


    【解决方案1】:

    当您使用第 3 方非 Angular 库时,您需要使用 $scope.$apply() 更新范围绑定:

    .then((willDelete) => {
            if (willDelete) {
                $scope.taggingRows.splice(i, 1);
                // console.log(" i " + i + " & " + "r " + r);
                $scope.taggingRowsAct.splice(i, 0);
    
                $scope.$apply();  
    
                swal("Your file has been deleted!", {
                    icon: "success",
                })
    
            } else {
                swal("Your file was not deleted!");
                console.log("r1canceled" + r);
                r = false;
                console.log("r2canceled" + r);
            }
        });
    

    阅读更多:https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$apply

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-07
      • 2022-12-23
      • 2023-01-12
      • 2020-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多