【问题标题】:meteor add sweet alert for delete流星添加删除的甜蜜警报
【发布时间】:2023-03-08 21:20:02
【问题描述】:

我不知道在哪里以及如何放置删除线:

Clanovi.remove(this._id);

在甜蜜的警报中,我尝试这样:

'click .btn-danger'()
{

    swal({
      title: "Are you sure?",
      text: "You will not be able to recover this imaginary file!",
      type: "warning",
      showCancelButton: true,
      confirmButtonColor: "#DD6B55",
      confirmButtonText: "Yes, delete it!",
      cancelButtonText: "No, cancel plx!",
      closeOnConfirm: false,
      closeOnCancel: false
    },
    function(isConfirm){
      if (isConfirm) {
        Clanovi.remove(this._id);
        swal("Deleted!", "Your imaginary file has been deleted.", "success");
      } 
      else
      {
        swal("Cancelled", "Your imaginary file is safe :)", "error");
      }
    });

}

这不起作用,我不知道该怎么做。它不会删除。

【问题讨论】:

    标签: meteor sweetalert


    【解决方案1】:

    很可能this 不是您所期望的。试试:

    'click .btn-danger'()
    {
        let that = this;
        console.log(that._id);
        swal({
          title: "Are you sure?",
          text: "You will not be able to recover this imaginary file!",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "Yes, delete it!",
          cancelButtonText: "No, cancel plx!",
          closeOnConfirm: false,
          closeOnCancel: false
        },
        function(isConfirm){
          if (isConfirm) {
            Clanovi.remove(that._id);
            swal("Deleted!", "Your imaginary file has been deleted.", "success");
          } else {
            swal("Cancelled", "Your imaginary file is safe :)", "error");
          }
        });
    
    }
    

    或者 - 您尚未设置允许/拒绝规则以允许在客户端上进行删除。

    从安全角度来看,您最好调用一个方法来删除,而不是在客户端上执行它。

    【讨论】:

      【解决方案2】:

      以下是对我有用的示例:

      const answer = await swal({
        title: 'Are you sure?',
        text: 'You will not be able to recover this imaginary file!',
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#dd6b55',
        cancelButtonColor: '#d44',
        confirmButtonText: 'Yes, delete it!',
        cancelButtonText: 'No, keet it',
        closeOnConfirm: false
      })
      

      如果用户确认,答案将有{value: true}

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-03
        • 2023-03-20
        • 2018-07-25
        • 2022-08-06
        相关资源
        最近更新 更多