【发布时间】:2020-01-07 17:34:07
【问题描述】:
所以我有这个 json:
this.state = {
projects: [{
id: 10,
name: "Project 10",
runTimes: [{
id: 186,
name: "Do Homeworks",
start: "2020-W01",
end: "2020-W09",
project: 10,
users: [{
id: 1,
name: "Sander Cokart",
runTime: [
186
]
}]
}],
hidden: false
}, ]
}
我希望根据 runTimes.start & end 进行过滤,
我已经试过了:
const filtered = array.filter((project) => {
if (!project.hidden) {
if (project.runTimes.filter((runTime) => {
if (moment(runTime.start).isSameOrAfter(context.searchFrom) &&
moment(runTime.end).isSameOrBefore(context.searchTo)) {
return runTime;
}
}).length > 0) {
return project;
}
}
});
遗憾的是,在项目对象 RunTimes 数组中存在第二个 RunTime 时它不起作用。
有人有想法吗?
【问题讨论】:
-
array在array.filter中的值是多少?和this.state.projects.filter一样吗? -
是的,确实是 array = this.state.projects
标签: arrays json reactjs filter momentjs