在jquery完整日历中显示行和列的总数

时间:2015-11-25 09:15:30

标签: jquery json fullcalendar

我有一个Jquery完整日历。要在json中提取要在完整日历中显示的值。这是demo

完整日历HTML代码

<div id='calendar'></div>

完整日历Jquery代码

var $calendar = $('#calendar').fullCalendar({
header: {
    left: 'prev,next today',
    center: 'title',
    right: 'month,agendaWeek,agendaDay'
},
editable: true,
selectable: true,
selectHelper: true,
defaultView: 'month',
events: [
    {"title":"100","start":"Nov 1 2015"},   
    {"title":"50","start":"Nov 2 2015"},
    {"title":"100","start":"Nov 3 2015"},   
    {"title":"50","start":"Nov 4 2015"},
    {"title":"100","start":"Nov 5 2015"},   
    {"title":"50","start":"Nov 6 2015"},
    {"title":"100","start":"Nov 7 2015"},   
    {"title":"50","start":"Nov 8 2015"},
    {"title":"100","start":"Nov 9 2015"},   
    {"title":"50","start":"Nov 10 2015"},
    {"title":"100","start":"Nov 11 2015"},   
    {"title":"50","start":"Nov 12 2015"},
    {"title":"100","start":"Nov 13 2015"},   
    {"title":"50","start":"Nov 14 2015"},
    {"title":"100","start":"Nov 15 2015"},   
    {"title":"50","start":"Nov 16 2015"},
    {"title":"100","start":"Nov 17 2015"},   
    {"title":"50","start":"Nov 18 2015"},
    {"title":"100","start":"Nov 19 2015"},   
    {"title":"50","start":"Nov 20 2015"},
    {"title":"100","start":"Nov 21 2015"},   
    {"title":"50","start":"Nov 22 2015"},
    {"title":"100","start":"Nov 23 2015"},   
    {"title":"50","start":"Nov 24 2015"}

]
});

这就是我要找的: -

我想计算行和列的总数将它们显示在单独的div 中。以下是我要查找的Desired Output Sample

所需的输出样本

这可能吗?请编辑我的小提琴解决方案。提前致谢

1 个答案:

答案 0 :(得分:0)

FIDDLE EXAMPLE

工作代码:

var counts = [0,0,0,0,0,0,0];

var baseEvent = $('#calendar').fullCalendar( 'clientEvents')
baseEvent.forEach(function(event) {
    counts[event.start.getDay()] += parseInt(event.title);
});

console.log(counts);

是的,你可以,但你需要定义一个函数,它正在做mod 7到日期。

算法:

weekDayList[];

foreach events to event
   date = event.getDate();
   var mod = date.getDay()%7;
   weekDayList[mod].count += event.title;

当你这样做时,你会在一周内分开7个部分。

现在您可以使用;

写入html
weekDayList[0].count
weekDayList[1].count
weekDayList[2].count
weekDayList[3].count
.
.
.