我正在使用DHTMLX调度程序 ,我试图在弹出事件编辑器中点击删除按钮时删除一个事件,下面是我的代码参考。
scheduler.attachEvent("onEventDeleted", function(id,ev){ $.ajax({ url : "calendar.php", type: 'post', data: { event_id : id}, success: function(e){ if($.trim(e) === "success"){ alert("Event was successfully deleted"); } } }); });上面的代码工作(事件被成功删除),但问题是,当我从弹出编辑器中单击取消按钮时,'onEventDeleted'也会触发。 任何想法,帮助,建议,建议,请帮忙吗?
Im using DHTMLX scheduler and I'm trying to delete an event when click on the delete button in the popup event editor, below is my code reference.
scheduler.attachEvent("onEventDeleted", function(id,ev){ $.ajax({ url : "calendar.php", type: 'post', data: { event_id : id}, success: function(e){ if($.trim(e) === "success"){ alert("Event was successfully deleted"); } } }); });the above code works (The event was deleted successfully) but the problem is, the 'onEventDeleted' did also trigger when i click the cancel button from the popup editor. Any ideas, help, suggestions, recommendations, help please?
最满意答案
只有在创建新事件时按取消才会发生这种情况。 在这种情况下,预期会触发onEventDeleted,因为它会从日历中删除新创建的事件。 为了不将该更新发送到后端,您可以使用此方法http://docs.dhtmlx.com/scheduler/api__scheduler_getstate.html
因此,如果你更新代码如下,一切都应该是好的:
scheduler.attachEvent("onEventDeleted", function(id,ev){ if(scheduler.getState().new_event) return; $.ajax({ url : "calendar.php", type: 'post', data: { event_id : id}, success: function(e){ if($.trim(e) === "success"){ alert("Event was successfully deleted"); } } }); });It happens only if you press cancel while creating a new event. In this case triggering onEventDeleted is expected since it removes a newly created event from a calendar. In order not to send that update to the backend you can use this method http://docs.dhtmlx.com/scheduler/api__scheduler_getstate.html
So if you update code like following everything should be good:
scheduler.attachEvent("onEventDeleted", function(id,ev){ if(scheduler.getState().new_event) return; $.ajax({ url : "calendar.php", type: 'post', data: { event_id : id}, success: function(e){ if($.trim(e) === "success"){ alert("Event was successfully deleted"); } } }); });更多推荐
发布评论