当前位置: 移动技术网 > IT编程>开发语言>Java > JavaWeb项目FullCalendar日历插件使用的示例代码

JavaWeb项目FullCalendar日历插件使用的示例代码

2019年07月19日  | 移动技术网IT编程  | 我要评论

本文介绍了javaweb项目fullcalendar日历插件使用的示例代码,分享给大家,具体如下:

使用fullcalendar需要引用的文件

1.css文件

2.js文件

<link href="${base}/assets/global/plugins/fullcalendar/fullcalendar.min.css" rel="external nofollow" rel="stylesheet" type="text/css" />
<script src="${base}/assets/global/plugins/fullcalendar/fullcalendar.min.js"
    type="text/javascript"></script>

生成日历主界面

fullcalendar·里有个events属性,可以从数据库查询数据动态添加事项

events: function(start,end,timezone, callback) {
        //当前日期
        var date = this.getdate().format('yyyy-mm-dd');
        $.ajax({
          url: ctx + "/teach/attend-getcalendareventsbyclazzid.do",
          datatype: 'json',
          data: {
            calendarclazzid : function(){
              return calendarclazzid;
            },
            date : date
          },
          success: function(result) { 
            var events = [];
            $.each(result,function(index,r){
              var begintime = r.datetime.substring(0,11) + r.begintime.substring(11,20);
              var endtime = r.datetime.substring(0,11) + r.endtime.substring(11,20);
              if(r.numbers != 0) {
                events.push({
                  title : r.numbers + "人缺勤",
                  id : r.id,
                  start : begintime,
                  end : endtime,
                  backgroundcolor : r.numbers >= 3 ? metronic.getbrandcolor('red') :metronic.getbrandcolor('yellow')
                });
              } else {
                events.push({
                  title : "全部出勤",
                  id : r.id,
                  start : begintime,
                  end : endtime,
                  backgroundcolor : metronic.getbrandcolor('green')
                });
              }

            })
            callback(events);
          }
        });
      },

 可以给传递到后台的参数重新赋值,并刷新页面事项,可以调用如下代码:

$('#calendar').fullcalendar('refetchevents');

没选择班级之前默认日历界面

没选择班级之前默认日历界面 

选择不同的班级,ajax会根据不同的班级id以及当前日期到后台查询事项并刷新\

选择不同的班级,ajax会根据不同的班级id以及当前日期到后台查询事项并刷新

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网