Mik*_*son 7 javascript jquery calendar underscore.js momentjs
我正在使用clndr.js(http://kylestetz.github.io/CLNDR/)来显示假日小屋预订的日期.这些始终使用多日活动系统显示,因为最低预订为3天.我现在需要以不同的方式设计活动的第一天和最后一天,以显示它们是转换日.理想情况下,我会通过添加一个类来做到这一点td.这是我到目前为止:
JS
$('#calendar').clndr({
template: $('#calendar-template').html(),
weekOffset: 1,
daysOfTheWeek: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
targets: {
nextButton: 'clndr-next',
previousButton: 'clndr-previous'
},
multiDayEvents: {
startDate: 'start',
endDate: 'end'
},
events: events,
clickEvents: {
click: function(target) {
//alert(target);
}
}
});
Run Code Online (Sandbox Code Playgroud)
示例JSON
var events = [
{start:'2016-05-29T00:00:00+00:00',
end:'2016-06-01T00:00:00+00:00',
title:'Mrs A N Human',},
{start:'2016-08-10T00:00:00+00:00',
end:'2016-08-17T00:00:00+00:00',
title:'Mr A Person',}
];
Run Code Online (Sandbox Code Playgroud)
HTML /下划线
<div id="calendar">
<script type="text/template" id="calendar-template">
<table class="table">
<thead>
<tr>
<th class='clndr-previous'><</th>
<th colspan="5"><%= month %> <%= year %></th>
<th class='clndr-next'>></th>
</tr>
<tr>
<% _.each(daysOfTheWeek, function(day) { %>
<th class="header-day"><%= day %></th>
<% }); %>
</tr>
</thead>
<tbody>
<tr class="days"><% _.each(days, function(day, index) { %>
<td class="<%= day.classes %>" id="<%= day.id %>">
<span class="day-number">
<%= day.day %>
</span>
</td>
<% if ((index + 1) % 7 == 0) {
%> </tr><tr> <%
} %><% }); %>
</tr>
</tbody>
</table>
</script>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在努力找出如何针对那些第一天和最后几天来应用一些不同的造型.我正在使用moment.js,如果可以使用的话.非常感谢!
所以最终我花了一些时间看着使用Underscore和Moment来实现我追求的目标.下面是我更新的代码,使用Underscore中的条件来使用Moment检查日期,并在<td>必要时添加一个类.这与我在JSON数组中表示事件的方式相结合:
HTML /下划线
<div id="calendar">
<script type="text/template" id="calendar-template">
<table class="table">
<thead>
<tr>
<th class='clndr-previous'><</th>
<th colspan="5"><%= month %> <%= year %></th>
<th class='clndr-next'>></th>
</tr>
<tr>
<% _.each(daysOfTheWeek, function(day) { %>
<th class="header-day"><%= day %></th>
<% }); %>
</tr>
</thead>
<tbody>
<tr class="days">
<% _.each(days, function(day, index) { %>
<td class="<%= day.classes %> <% _.each(day.events, function(event) { %><% if( moment(event.start).isSame( day.date ) ){ %>start<% } %><% }); %> <% _.each(day.events, function(event) { %><% if( moment(event.end).isSame( day.date ) ){ %>end<% } %><% }); %>">
<span class="day-number"><%= day.day %></span>
</td>
<% if ((index + 1) % 7 == 0) { %> </tr><tr> <% } %>
<% }); %>
</tr>
</tbody>
</table>
</script>
</div>
Run Code Online (Sandbox Code Playgroud)
JSON
var events = [
{start:'2016-05-29',
end:'2016-06-01',
title:'Mrs A N Human',},
{start:'2016-08-10',
end:'2016-08-17',
title:'Mr A Person',}
];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
919 次 |
| 最近记录: |