使用json数据每天渲染

时间:2013-03-28 15:51:25

标签: jquery fullcalendar

我有一个网络服务,每天都会返回一种颜色:

({"total_rows":"96","rows":[
  {"row":{"date":"2013-01-01","airqualityindex":"50","categorycolorinteger":"-16718848"}},
  {"row":{"date":"2013-01-02","airqualityindex":"45","categorycolorinteger":"-16718848"}},
  {"row":{"date":"2013-01-03","airqualityindex":"57","categorycolorinteger":"-256"}},
  {"row":{"date":"2013-01-04","airqualityindex":"36","categorycolorinteger":"-16718848"}},
  {"row":{"date":"2013-01-05","airqualityindex":"42","categorycolorinteger":"-16718848"}},
  {"row":{"date":"2013-01-06","airqualityindex":"51","categorycolorinteger":"-256"}}
...]})

我想使用此Web服务返回的categorycolorinteger为每天单元格的背景颜色着色。我想我可以用dayRender做到这一点,但我还没有找到一个如何做到这一点的好例子。

谢谢,艾米

1 个答案:

答案 0 :(得分:1)

您可以循环上面的对象并适当设置背景颜色。像这样:

dayRender: function(date, cell) {
             // loop through your object here
             // here the date 2013-03-01 and the color red are passed from your loop
             if($.fullCalendar.formatDate(date, 'yyyy-MM-dd') === "2013-03-01")
                cell.css('background-color', 'red');
           }

如果有帮助,请告诉我!