显示加号图标在一天呈现在完整的日历

时间:2018-06-15 05:47:58

标签: javascript jquery fullcalendar fullcalendar-scheduler fullcalendar-3

我的默认视图是完整日历中的月视图 我在每日渲染事件中每天都会显示一个加号图标,但是对于即将到来的日期,所有日期都会显示加号图标

我想仅在启用日期或即将到来的日期显示加号图标,而不是过去的日期,请帮我这样做。

以下是我的日历脚本

<script type="text/javascript">
    $(document).ready(function() {   
         /* initialize the calendar
         -----------------------------------------------------------------*/
        var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();
        $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            dayRender: function (date,cell) {
              cell.prepend('<i class="fa fa-plus" aria-hidden="true"></i>');
            },
            selectable: true,
            selectHelper: true, 
            editable: true,            
            eventLimit: true, // allow "more" link when too many events
            events: [
            <?php if(!empty($calendar)){ foreach ($calendar as $schdate){ 
                $dte =  date('Y-m-d', strtotime($schdate['schedule_date'])); ?>
                {
                    title: '<?php echo $schdate['schedule_title']; ?>',
                    start: '<?php echo $dte; ?>'

                },
            <?php } } ?>            

            ]
        });
    });
</script>

1 个答案:

答案 0 :(得分:1)

试试这个......
此getDates()函数用于检索当前日期

function getDates()
{
    var date = new Date();
        var cellYear = date.getFullYear();
        var cellMonth = (date.getMonth() + 1 <10)?'0'+(date.getMonth() + 1) : (date.getMonth() + 1);
        var cellDay = (date.getDate()<10)?'0'+(date.getDate()):(date.getDate());
        var newDate = cellYear+"-"+cellMonth+"-"+cellDay;   
        return newDate;
}

dayRender: function (date, cell) {
            var cellYear = date.year();
            var cellMonth = (date.month() + 1 <10)?'0'+(date.month() + 1) : (date.month() + 1);
            var cellDay = (date.date()<10)?'0'+(date.date()):(date.date());
            var newDate = cellYear+"-"+cellMonth+"-"+cellDay;

            if(newDate >= getDates()){                  
                cell.append('<i class="fa fa-plus" aria-hidden="true"></i>');                   
            }       
        },