以下の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