通过json提要中的事件执行Apploop

通过json提要中的事件执行Apploop,json,fullcalendar,Json,Fullcalendar,在下面的jquery中,在ajax post成功后使用警报时,我看到了很多事件对象 如何访问每个事件的详细信息并相应地进行更改 eventSources: [ { url: 'json-events.php', type: 'POST', error: function (data) { alert('there was an error while fetching events!' + data.msge); }, success: f

在下面的jquery中,在ajax post成功后使用警报时,我看到了很多事件对象

如何访问每个事件的详细信息并相应地进行更改

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
//批准功能
$('.approve')。单击(函数(calEvent、jsEvent、view、getid){
//获取事件的id
var getid=$('.approve').attr('id');
如果($(this.html()=“是”){
//要插入数据库的AJAX post
$.post(“ajax.php”{
行动:'批准',
颜色:“绿色”
},
功能(数据){
var fancyContent=(“”+data.msge+”

); $.fancybox({ 内容:fancyContent }); }“json”); //获取事件 var eventObject=$('#calendar').fullCalendar('clientEvents',getid); //设置事件颜色 eventObject.backgroundColor='绿色'; eventObject.eventBorderColor='绿色'; eventObject.title=event.title+“已批准”; //以某种方式更新事件? $('#calendar').fullCalendar('updateEvent',eventObject); }否则{ //封闭式通风箱 $.fancybox.close(); }//如果结束 }); // 单击“批准”结束
您可以像这样循环JSON响应:

success : function( responseData ) {
  $.each( function( index, responseObj ) {
    if( responseObj.approved === "1" ) {
      responseObj.title += " approved";
      responseObj.className = "approved";
    }
    else {
      responseObj.title += " waiting approval";
      responseObj.className = "unapproved";
    }
  } );

}
您将无法使用此过滤样式设置每个事件类型的颜色

您可以将每种类型分解为各自的事件源,例如:

eventSources : [
  {
    url : 'json-events.php?approved=y',
    color : 'green'
    // ... success() and other attributes go here
  },
  {
    url : 'json-events.php?approved=n',
    color : 'red'
    // ... success() and other attributes go here
  }
]

谢谢你的回复。在用户在一个奇特的框中单击“是”之后,我使用ajax帖子来批准每个事件。如果用户单击“是”,有没有办法将事件涂成绿色?我已经更新了我的代码非常感谢