当我在下面的 jquery 中成功发布 ajax 后使用警报时,我看到了很多事件对象。
我如何访问每个事件的详细信息并相应地更改它们?
eventSources: [
{
url: 'json-events.php',
type: 'POST',
error: function (data) {
alert('there was an error while fetching events!' + data.msge);
},
success: function (data) {
alert(data);
// how do i loop through the event objects and filter which ones are approved == 1?
if(data.approved == "1") {
// How do I then change the properties of each event that is approved?
event.title = title + "approved";
event.Color = 'green';
var event.className = "approved";
} else{
var event.title = title + "awaiting approval";
event.Color = 'red';
var event.className = "unapproved";
}
}
}]
更新:批准后更改单个事件的颜色
// approve function
$('.approve').click(function (calEvent, jsEvent, view, getid) {
// Get id of event
var getid = $('.approve').attr('id');
if ($(this).html() == "yes") {
// AJAX post to insert into DB
$.post("ajax.php", {
action: 'approve',
color: 'green'
},
function (data) {
var fancyContent = ('<div class="header"><p>' + data.msge + '</p></div>');
$.fancybox({
content: fancyContent
});
}, "json");
// get event
var eventObject = $('#calendar').fullCalendar( 'clientEvents', getid );
// set event colors
eventObject.backgroundColor = 'green';
eventObject.eventBorderColor = 'green';
eventObject.title = event.title + " approved";
// update event somehow?
$('#calendar').fullCalendar('updateEvent', eventObject);
} else {
// close fancybox
$.fancybox.close();
} // end of if
}); // end of approve click