根据使用 Alpine.js 选择的日期范围进行过滤
我正在尝试过滤在选定的 fromDate
和 toDate
期间处于活动状态的董事 $inactiveDirectors
。 董事的有效日期是从生效日期 (director. effective_date
) 到辞职/免职日期 (director.release_date
)。如果用户没有选择toDate
,它将被假定为当前日期。
功能:
function loadDirectors() {
return {
fromDate: ""
, toDate: ""
, fromDateObj: null
, toDateObj: null
, directorsList: @json($inactiveDirectors)
, get filteredDirectors() {
if (this.fromDate === "") {
return this.directorsList;
}
this.fromDateObj = new Date(this.fromDate);
if (this.toDate === "") {
this.toDateObj = null;
} else {
this.toDateObj = new Date(this.toDate);
}
return this.directorsList.filter((director) => {
let effective_date_obj = new Date(director.effective_date);
let release_date = new Date(director.release_date);
if (this.fromDateObj.getTime() < effective_date_obj.getTime()) {
if (this.toDateObj) {
if (this.toDateObj.getTime() > release_date.getTime()) {
return director;
} else {
return director;
}
}
}
});
}
}
}
我一直在尝试使用 Alpine.js 进行过滤,但还没有成功。如果您能找到解决此问题的方法,我们将不胜感激。
谢谢
Im trying to filter the directors $inactiveDirectors
who were active during the selected fromDate
and the toDate
.
Directors will be active from their effective date (director.effective_date
) to their resigned/removed date (director.release_date
). And if the user did not pick a toDate
it will be assumed to as the current date.
The function:
function loadDirectors() {
return {
fromDate: ""
, toDate: ""
, fromDateObj: null
, toDateObj: null
, directorsList: @json($inactiveDirectors)
, get filteredDirectors() {
if (this.fromDate === "") {
return this.directorsList;
}
this.fromDateObj = new Date(this.fromDate);
if (this.toDate === "") {
this.toDateObj = null;
} else {
this.toDateObj = new Date(this.toDate);
}
return this.directorsList.filter((director) => {
let effective_date_obj = new Date(director.effective_date);
let release_date = new Date(director.release_date);
if (this.fromDateObj.getTime() < effective_date_obj.getTime()) {
if (this.toDateObj) {
if (this.toDateObj.getTime() > release_date.getTime()) {
return director;
} else {
return director;
}
}
}
});
}
}
}
I've been trying to filter using Alpine.js with no luck yet. Appreciate if you could find a way to resolve this.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了。供您参考:
I resolved it. For your reference: