需要在给定日期范围内写入 ngRx select 或 select 数据?
Need to write ngRx selector to select data between given date range?
我需要写一个 selector 到 select 实体数组列表数据。数据数组对象内容为 startDate 和 EndDate。但有些对象没有结束日期。如果 -> endDate 可用,我需要检查结束日期。如果结束日期为空,则该数据也应添加到地图中。
需要一些专家的帮助来纠正这个 select 或逻辑。它将给出声纳问题也需要使用 '!==' 和 'Variables should not be shadowed' 就像一个 'select all' .
Start, End -> check Pass date between or Equal date range
The only start -> Check start date on or before the given date.
我的约会对象select逻辑:
const selectReviewState =
createSelector(selectAdminFeature,
(appState) => appState.ReviewState);
const {
selectAll,
} = ReviewAdaptor.getSelectors();
/**
* Select all Review as an array
*/
const selectReviews = createSelector(
selectReviewState,
selectAll
);
/**
*
* Select Review data with in given range , during one year period past to future
*
*/
export const selectAllReviewsDetailsModel = (planedDate: Date) => createSelector(
selectReviews,
(selectAll: ReviewModel[]) =>
selectAll.filter(date => date.startDateTime.getTime() <= planedDate.getTime() &&
(date.endDateTime != null && date.endDateTime.getTime() >= planedDate.getTime()))
);
moment
是非常强大的日期库,可以使日期计算变得容易。
您可以像下面这样更新选择器
import moment from 'moment';
export const selectAllReviewsDetailsModel => createSelector(
selectReviews,
(selectAll: ReviewModel[], props) => {
const { planedDate } = props;
return selectAll.filter(date =>
moment(date.startDateTime).isSameOrBefore(moment(planedDate)) &&
moment(date.endDateTime).isValid() ? moment(date.startDateTime).isSameOrAfter(moment(planedDate)) : true)
});
如果您注意到我将 planedDate
作为 props 传递,并且在组件方面您可以使用此选择器
const result = this.store.pipe(selectAllReviewsDetailsModel, { planedDate: '09/12/2002' })
我需要写一个 selector 到 select 实体数组列表数据。数据数组对象内容为 startDate 和 EndDate。但有些对象没有结束日期。如果 -> endDate 可用,我需要检查结束日期。如果结束日期为空,则该数据也应添加到地图中。 需要一些专家的帮助来纠正这个 select 或逻辑。它将给出声纳问题也需要使用 '!==' 和 'Variables should not be shadowed' 就像一个 'select all' .
Start, End -> check Pass date between or Equal date range
The only start -> Check start date on or before the given date.
我的约会对象select逻辑:
const selectReviewState =
createSelector(selectAdminFeature,
(appState) => appState.ReviewState);
const {
selectAll,
} = ReviewAdaptor.getSelectors();
/**
* Select all Review as an array
*/
const selectReviews = createSelector(
selectReviewState,
selectAll
);
/**
*
* Select Review data with in given range , during one year period past to future
*
*/
export const selectAllReviewsDetailsModel = (planedDate: Date) => createSelector(
selectReviews,
(selectAll: ReviewModel[]) =>
selectAll.filter(date => date.startDateTime.getTime() <= planedDate.getTime() &&
(date.endDateTime != null && date.endDateTime.getTime() >= planedDate.getTime()))
);
moment
是非常强大的日期库,可以使日期计算变得容易。
您可以像下面这样更新选择器
import moment from 'moment';
export const selectAllReviewsDetailsModel => createSelector(
selectReviews,
(selectAll: ReviewModel[], props) => {
const { planedDate } = props;
return selectAll.filter(date =>
moment(date.startDateTime).isSameOrBefore(moment(planedDate)) &&
moment(date.endDateTime).isValid() ? moment(date.startDateTime).isSameOrAfter(moment(planedDate)) : true)
});
如果您注意到我将 planedDate
作为 props 传递,并且在组件方面您可以使用此选择器
const result = this.store.pipe(selectAllReviewsDetailsModel, { planedDate: '09/12/2002' })