日期之间的 jQuery 同位素过滤
我正在制作一个事件日历,我想显示两个日期选择器字段之间的所有事件,我将不胜感激每一个提示。
同位素代码:
// filter the events by datepicker fields when search button is clicked
$('#calbtn').on( 'click', function( event ) {
// get startdate from datepicker field
var startdate = $('#calstartday').val();
// get enddate from datepicker field
var enddate = $('#calendday').val();
$grid.isotope({
filter: '[data-startdate="' + startdate + '"], [data-enddate="' + enddate + '"]'
});
});
到目前为止,该代码有效,但仅显示具有确切开始日期和结束日期的事件。
这就是用于演示目的的事件的样子:
<div data-startdate="2022-01-01" data-enddate="2022-04-24" class="event__item">
<div data-startdate="2023-01-01" data-enddate="2022-04-24" class="event__item">
<div data-startdate="2024-01-01" data-enddate="2022-04-24" class="event__item">
<div data-startdate="2025-01-01" data-enddate="2022-04-24" class="event__item">
我的想法是: 我确信我需要一个自定义函数来进行过滤,在其中比较两个时间戳并检查事件是否在两个所选日期之间。但我没有在文档或其他地方找到如何返回有效事件的方法。
有人给我提示吗?
I'm working on an event calendar and I would like to show all events between two datepicker fields and I would be grateful for every tip.
Isotope Code:
// filter the events by datepicker fields when search button is clicked
$('#calbtn').on( 'click', function( event ) {
// get startdate from datepicker field
var startdate = $('#calstartday').val();
// get enddate from datepicker field
var enddate = $('#calendday').val();
$grid.isotope({
filter: '[data-startdate="' + startdate + '"], [data-enddate="' + enddate + '"]'
});
});
This is working so far, but only shows the events with the exact start- and enddate.
And this is how the events are looking like for demo purpose:
<div data-startdate="2022-01-01" data-enddate="2022-04-24" class="event__item">
<div data-startdate="2023-01-01" data-enddate="2022-04-24" class="event__item">
<div data-startdate="2024-01-01" data-enddate="2022-04-24" class="event__item">
<div data-startdate="2025-01-01" data-enddate="2022-04-24" class="event__item">
My thoughts are:
I'm sure that I need a custom function to filter for, where I compare the two timestamps and check if the event is between the two chosen dates. But I didnt found an approach inside the documenation or elsewhere, how to return the valid events.
Does anybody has a hint for me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用过滤函数。
Use a filter function.