[英]jquery ui dialog - button click event handlers
I'm a js noob. 我是js菜鸟。 I'm using the jquery FullCalendar plugin which exposes an eventClick(calEvent, jsEvent, view) event which is called when you click on an event on the calendar.
我正在使用jQuery FullCalendar插件,该插件公开一个eventClick(calEvent,jsEvent,view)事件,当您在日历上单击某个事件时会调用该事件。 In my event handler I want to pop up a dialog asking if the user wants to edit just one occurrence of a recurring event or the whole event.
在我的事件处理程序中,我想弹出一个对话框,询问用户是否只想编辑一次重复发生的事件还是整个事件。 The problem is that the button click handlers for THAT dialog need to have access to the calEvent variable, but I have to instantiate the dialog inside $(document).ready but outside of the eventClick function.
问题在于,该对话框的按钮单击处理程序需要有权访问calEvent变量,但是我必须在$(document).ready内但在eventClick函数之外实例化该对话框。
Here's my code so far: 到目前为止,这是我的代码:
$(document).ready(function() {
$('#calendar').fullCalendar({
events: getEvents,
header: {
left: 'title',
center: 'prev,next',
right: 'today month agendaWeek agendaDay'
},
theme: true,
eventClick: function(calEvent, jsEvent, view) {
if(calEvent.readOnly == true) {
return;
}
if(calEvent.recurring) {
if(calEvent.persisted) {
editOccurrence(calEvent);
} else {
$("#edit_type_dialog").dialog("open");
}
} else {
editEvent(calEvent);
}
}
});
$("#edit_type_dialog").dialog({
modal:true,
autoOpen: false,
buttons: {
All:function() {
$(this).dialog("close");
editEvent(calEvent);
},
This:function() {
$(this).dialog("close");
editOccurrence(calEvent);
},
Cancel:function() {
$(this).dialog("close");
}
}
});
function getEvents(start, end, callback) {
//get some events
}
function editEvent(calEvent) {
alert("event edited");
}
function editOccurrence(calEvent) {
alert("occurrence edited");
}
});
So the question boils down to: how do I get the calEvent over to the button click event handlers in the edit_type_dialog from the eventClick function? 因此,问题归结为:如何从eventClick函数将calEvent传递到edit_type_dialog中的按钮单击事件处理程序?
Here's what I did (not sure if it's recommendable, but it works): 这是我所做的(不确定它是否值得推荐,但可以使用):
1) Move the dialog instantiation into the eventClick method, thereby giving it access to the calEvent variable. 1)将对话框实例化到eventClick方法中,从而使它可以访问calEvent变量。 2) Outside the fullCalendar instantiation, but still within $(document).ready() I added $("#edit_type_dialog").hide()
2)在fullCalendar实例化之外,但仍在$(document).ready()内,我添加了$(“#edit_type_dialog”)。hide()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.