如何获取日历渲染日期单元格的日期

编程入门 行业动态 更新时间:2024-10-11 03:24:24
本文介绍了如何获取日历渲染日期单元格的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一种情况,我需要在每个事件URL中添加日期(对于事件url,我使用jquery添加href attr)查询字符串,但在检查文档后,我发现 eventClick 和 eventRender 不会返回显示事件的单元格的日期。

我试过Google,发现了一些棘手的解决方案,使用 eventClick 回调并使用第X页和Y,然后得到最近的元素,其中包含具有特定单元格日期的数据属性,但 eventClick:function(event ,jsEvent,view){ var clickedDate = $ .nearest({x:jsEvent.pageX,y:jsEvent.pageY},'.fc-day')。attr('data-date'); alert(clickedDate); }

但是当我有多个事件在同一天的细胞和更多的事件将显示在弹出窗口中。 注意: $ .nearest 是jquery插件,用于从给定的X,Y位置中找到最近的元素 注意:我使用v2

解决方案

这对你的工作是否足够好?

http:/ /jsfiddle/3E8nk/531/

$('#calendar')。fullCalendar({ header:{ left:'prev,next today', center:'title', right:'month,agendaweek,agendaDay'}, defaultDate:'2014-06-12', editable:true, eventRender:function(event,element,view){ var start = event.start.clone ().startOf('day'); var end = event.end?event.end.clone()。endOf('day'):start.clone()。endOf一天'); //已知错误:我们得到所有感人的事件,而不仅仅是在我们点击 var events = $('#日历').fullCalendar(' clientEvents'); var touchingEvents = events.filter(function(event){ var eventStartWithin = event.start.isWithin(start,end), eventEndWithin = event。 end?event.end.isWithin(start,end):false; return eventStartWithin || eventEndWithin; }); console.log(touchingEvents); },事件:[ {标题:'全天事件',开始:'2014-06-01'}, { title:'Long Event', start:'2014-06-07',结束:'2014-06-10' }, { id:999, title:'Repeating Event', start:'2014-06-09T16:00:00'}, { id:999,标题:'重复活动',开始:'2014-06-16T16:00:00'}, { title:'会议',开始:'2014-06-12T10:30:00',结束:'2014-06-12T12:30:00' }, { title:'Lunch', start:'2014-06-12T12:00:00'}, { title :'生日派对',开始:'2014-06-1 3T07:00:00'}, { title:'Click for Google', url:'google/',开始:'2014-06-28'} ] });

I've a situation where I need to get the date to attach in each event url (For event url's I'm adding the href attr using jquery) query string but after checking the docs I found both eventClick and eventRender do not returns the date of cell upon which event is showing.

I tried google for it and found tricky solutions using the eventClick callback and use page X and Y and then get the nearest element which holds the data attribute with date for the particular cell date but

eventClick:function(event,jsEvent,view){ var clickedDate = $.nearest({x: jsEvent.pageX, y: jsEvent.pageY}, '.fc-day').attr('data-date'); alert(clickedDate); }

But this solutions fails when I've multiple event on the same date cell and more events will be shown in a popup. Note : $.nearest is the jquery plugin to find the nearest element from given X,Y postions

Note : I'm using v2

解决方案

Does this work sufficiently well for you?

jsfiddle/3E8nk/531/

$('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, defaultDate: '2014-06-12', editable: true, eventRender: function(event, element, view) { var start = event.start.clone().startOf('day'); var end = event.end ? event.end.clone().endOf('day') : start.clone().endOf('day'); //Known bug: We get all "touching" events and not just necessarily events on the day we clicked var events = $('#calendar').fullCalendar('clientEvents'); var touchingEvents = events.filter(function(event) { var eventStartWithin = event.start.isWithin(start, end), eventEndWithin = event.end ? event.end.isWithin(start, end) : false; return eventStartWithin || eventEndWithin; }); console.log(touchingEvents); }, events: [ { title: 'All Day Event', start: '2014-06-01' }, { title: 'Long Event', start: '2014-06-07', end: '2014-06-10' }, { id: 999, title: 'Repeating Event', start: '2014-06-09T16:00:00' }, { id: 999, title: 'Repeating Event', start: '2014-06-16T16:00:00' }, { title: 'Meeting', start: '2014-06-12T10:30:00', end: '2014-06-12T12:30:00' }, { title: 'Lunch', start: '2014-06-12T12:00:00' }, { title: 'Birthday Party', start: '2014-06-13T07:00:00' }, { title: 'Click for Google', url: 'google/', start: '2014-06-28' } ] });

更多推荐

如何获取日历渲染日期单元格的日期

本文发布于:2023-11-23 04:14:55,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   单元格   日历

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!