<script type="text/javascript">
$(function() {
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'
},
firstDay:1,
editable: true,
timeFormat: 'H:mm',
axisFormat: 'H:mm',
events: [
{
title: '全天计划\r\n#####\r\n写代码',
start: new Date(y, m, 1)
},
{
title: '张家界四日游',
start: new Date(y, m, d-5),
end: new Date(y, m, d-2)
},
{
id: 999,
title: '电话回访客户',
start: new Date(y, m, d-6, 16, 0),
allDay: true
},
{
id: 999,
title: '电话回访客户',
start: new Date(y, m, d+4, 16, 0),
allDay: false
},
{
title: '视频会议',
start: new Date(y, m, d, 10, 30),
allDay: false
},
{
title: '中秋放假',
start: '2013-09-19',
end: '2013-09-21',
},
{
title: '午饭',
start: new Date(y, m, d, 12, 0),
end: new Date(y, m, d, 14, 0),
allDay: false
},
{
title: '生日聚会',
start: new Date(y, m, d+1, 19, 0),
end: new Date(y, m, d+1, 22, 30),
allDay: false
},
{
title: '访问Helloweba主页',
start: new Date(y, m, 28),
end: new Date(y, m, 29),
url: 'http://helloweba.com/'
}
]
});
});
</script>
以上代码 我怎么events这个用循环写东西在里面 谢谢各位大佬
1 <script type="text/javascript"> 2 $(function() { 3 var date = new Date(); 4 var d = date.getDate(); 5 var m = date.getMonth(); 6 var y = date.getFullYear(); 7 8 var events = [[ 9 { 10 title: '全天计划\r\n#####\r\n写代码', 11 start: new Date(y, m, 1) 12 }, 13 { 14 title: '张家界四日游', 15 start: new Date(y, m, d-5), 16 end: new Date(y, m, d-2) 17 }, 18 { 19 id: 999, 20 title: '电话回访客户', 21 start: new Date(y, m, d-6, 16, 0), 22 allDay: true 23 }, 24 { 25 id: 999, 26 title: '电话回访客户', 27 start: new Date(y, m, d+4, 16, 0), 28 allDay: false 29 }, 30 { 31 title: '视频会议', 32 start: new Date(y, m, d, 10, 30), 33 allDay: false 34 }, 35 { 36 title: '中秋放假', 37 start: '2013-09-19', 38 end: '2013-09-21', 39 }, 40 { 41 title: '午饭', 42 start: new Date(y, m, d, 12, 0), 43 end: new Date(y, m, d, 14, 0), 44 allDay: false 45 }, 46 { 47 title: '生日聚会', 48 start: new Date(y, m, d+1, 19, 0), 49 end: new Date(y, m, d+1, 22, 30), 50 allDay: false 51 }, 52 { 53 title: '访问Helloweba主页', 54 start: new Date(y, m, 28), 55 end: new Date(y, m, 29), 56 url: 'http://helloweba.com/' 57 }] 58 $('#calendar').fullCalendar({ 59 header: { 60 left: 'prev,next today', 61 center: 'title', 62 right: 'month,agendaWeek,agendaDay' 63 }, 64 firstDay:1, 65 editable: true, 66 timeFormat: 'H:mm', 67 axisFormat: 'H:mm', 68 events: events 69 70 }); 71 72 }); 73 </script>
以循环的方式写在里面,只需要改动外部的变量events ,我不太清楚你的数据结构,这里我只是假设下 你的数据来源格式如下
eventsData= [ ... { title:"", start:"",
end :"", isFullDay:false, url:null } ... ]
这里用一个for 循环将上方代码(标注黄色地方)替换下面代码
var events=[]; for (var i = 0 ,length =eventsData.length ; i < length ; i++){ var evtData =eventsData[i] ; var event = {}; event.fullDay = evtData.isFullDay ; event.start = evtData.start ; event.end = evtData.end ; event.url = evtData.url ; events.push(event); }
具体fullCalendar的使用文档 地址如下(你可以看下官方的demo 去理解):
https://fullcalendar.io/docs/event_data/events_array/
写个方法,里面用for循环将数据拼接起来返回