zone.js: 140 Uncaught TypeError: Cannot read property 'remove'

感情迁移 提交于 2019-12-05 04:22:45

The key difference between native confirm method and custom modal window - native confirm method is synchronous.

When method is synchronous and you clicks Ok/Cancel in native confirm dialog, $(".pai-del-menu").blur even occurs, but executes only after $(".pai-del-menu").click was finished, so everything works fine.

When method is asynchronous and you clicks Ok/Cancel on modal window, $(".pai-del-menu").blur even occurs and executes immediately, removing pai_to_delete reference, so inside $(".pai-del-menu").click event pai_to_delete is already null.

All you need is to assign pai_to_delete to another variable right before kendoWindow creation and use it inside $(".pai-del-menu").click event:

$(".pai-del-menu").blur(function() {
  $(this).hide();
  pai_to_delete = null;
});

$(".pai-del-menu").click(function() {
  $(this).hide();
  if (pai_to_delete != null) {
    var paiToDelete = pai_to_delete;  // <----
    var kendoWindow = $("<div />").kendoWindow({
      title: "Confirm",
      resizable: false,
      modal: true,
      height: 100,
      width: 400
    });

    kendoWindow.data("kendoWindow")
      .content($("#delete-confirmation").html())
      .center().open();

    $(jumping).on("click", "#playerDocumentOk", function() {
      paiToDelete.remove();  // <----
      kendoWindow.data("kendoWindow").close();
    });

    $(jumping).on("click", "#playerDocumentCancel", function() {
      kendoWindow.data("kendoWindow").close();
    });
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!