javascript - fullcalendar 通过弹出模式奇怪的行为删除事件

标签 javascript jquery popup fullcalendar

我已将 fullcalendar 事件删除弹出模式。 这在一定程度上有效,但存在奇怪的行为。 我是这方面的新手,所以我尝试了几种不同的方法,但我无法消除这种奇怪的行为。 我不知道如何使 jsfiddle 重现确切的行为而不复制我的所有代码。但我的代码包含很多额外的东西。所以我无法提供jsfiddle。这里只给出相关代码。但我认为对此有丰富经验的人。我认为他们可以很容易地看穿代码。我非常感谢您的建议。我在这上面花了太多时间。 奇怪的行为是事件通过弹出模式删除,它删除了先前通过关闭按钮关闭的其他事件。下面的解释包含详细信息。

我做了这样的:

1) 弹出模式的 div 代码

<div class="modal fade" id="modalRemove" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
      </div>
      <div class="modal-body">
       <h4>Are you sure to remove the event?</h4>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" id="close" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-danger" id="removeBtn" data-dismiss="modal">Remove</button>
      </div>
    </div>
  </div>
</div>

2) 当单击事件时 -> 弹出模式显示 -> 然后可以选择(单击)关闭按钮或删除弹出模式上的按钮

eventRender: function (event, element){  
    element.click(function() {
        $('#modalRemove').modal();
        $('#eventTitle').html(event.title);
        $("#removeBtn").click(function() {  
             $('#calendar').fullCalendar('removeEvents',event._id); 
        });
    });
},

什么有效

  1. 弹出模式正在运行
  2. 关闭按钮,删除按钮正在工作
  3. 在弹出模式上按下删除按钮时事件将被删除

什么是奇怪的行为

  1. 假设有两个事件:test1、test2(image1)

enter image description here

  • 我点击了 test1 事件,然后出现弹出模式(image2)
  • enter image description here

  • 然后,我单击 test1 弹出窗口上的关闭按钮(未删除)-> 弹出窗口消失 -> test1 事件仍然在 fullcalendar 上,因为它应该是。 ====> 直到这里工作正常

  • 然后,我单击 test2 事件 -> 弹出模式如图 2 所示 -> 按 test2 的删除按钮 -> [问题]然后 test1、test2 事件都被删除

  • 为什么它会在 1、2、3、4 步骤后删除这两个事件?

    最佳答案

    试试这个:

    eventRender: function(event, element) {
      element.attr('href', 'javascript:void(0);');
      element.click(function() {
        //set the modal values and open
        $('#eventTitle').html(event.title);
    
        // Rebind the Remove button click handler
        $("#removeBtn").off('click').on('click', function(e) {
            $('#calendar').fullCalendar('removeEvents', event._id);
        });
    
        $('#modalRemove').modal();
      });
    }
    

    请注意,在绑定(bind)特定事件之前,如何通过 off() 取消所有 click 事件与 #removeBtn 按钮的绑定(bind)。

    (在您的代码中,每次单击日历中的事件时,该事件的新 click 处理程序都会绑定(bind)到 #removeBtn。因此,当您最终单击“删除”时“执行了多个处理程序。)

    关于javascript - fullcalendar 通过弹出模式奇怪的行为删除事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30261358/

    相关文章:

    javascript - bool 玛卡的简单 jQuery 切换不起作用

    jquery - 快速路线注册 Ajax 返回 POST http ://localhost:3004/signup/404

    javascript - Backbone : fetch and scope

    popup - 如何关闭 Liferay 中的弹出窗口?

    php - 仅向用户显示一次警报

    java - 测试时如何在 JOptionPane 上自动单击“确定”?

    javascript - 单击链接时获取 TD 字段的值

    javascript - 有没有办法在不使用全局变量的情况下在 jquery 的 hover() 中的两个函数之间共享变量?

    javascript - KnockoutJS 在模型上选择

    javascript - Angularjs - 指令 Controller 加载速度比应用程序 Controller 快 - 值未定义