全日历在移动时改变颜色



我有一个完整的日历,其中包含几个不同用户的条目。我已经成功地为每个用户的日历条目设置了不同的颜色。这一切都可以工作,除了如果我将一个日历条目(移动)到另一个日期,颜色会变回默认值。

json看起来像这样

{  
   "events":[  
      {  
         "title":"tkt[14411]",
         "start":"2015-07-09T06:00:00.196-0500",
         "end":"2015-07-09T08:00:00.196-0500",
         "id":"7",
         "userID":"1",
         "calColor":"#ff0000",
         "className":"ticketSrc_1",
         "custom":"test text here"
      },
      {  
         "title":"tkt[14412]",
         "start":"2015-07-11T06:00:00.196-0500",
         "end":"2015-07-11T08:00:00.196-0500",
         "id":"7",
         "userID":"2",
         "calColor":"#ffff00",
         "className":"ticketSrc_2",
         "custom":"test text here"
      }      
   ],
   "error":"0"
}
我添加事件和改变颜色的代码是这样的:
// remove duplicate events
for(var i=0;i<=json.events.length-1;i++){
    $('#calendar').fullCalendar("removeEvents",json.events[i].id);
}
// set colors for each user
$.when(
    $('#calendar').fullCalendar("addEventSource",json)
  ).done(function(){
      var cname="";
            for(var i=0;i<=json.events.length-1;i++){
                cname=".ticketSrc_"+json.events[i].userID;  
                $(cname).css("background",json.events[i].calColor);
            }                     
});

解决方案是在json

中传递一个"color"参数。
{  
   "events":[  
      {  
         "title":"tkt[14411]",
         "start":"2015-07-09T06:00:00.196-0500",
         "end":"2015-07-09T08:00:00.196-0500",
         "id":"7",
         "userID":"1",
         "color":"#ff0000",
         "className":"ticketSrc_1",
         "custom":"test text here"
      },
      {  
         "title":"tkt[14412]",
         "start":"2015-07-11T06:00:00.196-0500",
         "end":"2015-07-11T08:00:00.196-0500",
         "id":"7",
         "userID":"2",
         "color":"#ffff00",
         "className":"ticketSrc_2",
         "custom":"test text here"
      }      
   ],
   "error":"0"
}

相关内容

  • 没有找到相关文章

最新更新