Javascript 修改Meteor React ToDo列表示例以显示在时间范围内创建的列表项

Javascript 修改Meteor React ToDo列表示例以显示在时间范围内创建的列表项,javascript,mongodb,meteor,meteor-react,Javascript,Mongodb,Meteor,Meteor React,我正在学习这里的Meteor React Todo列表教程 根据,我们可以添加一个按钮来隐藏已签出的todo项。我们通过查询数据库中检查为true的项来实现这一点 if (this.state.hideCompleted) { // If hide completed is checked, filter tasks query = {checked: {$ne: true}}; } 如果我只想显示在过去30分钟内创建的todo项,即todo项在30分钟

我正在学习这里的Meteor React Todo列表教程

根据,我们可以添加一个按钮来隐藏已签出的todo项。我们通过查询数据库中检查为true的项来实现这一点

if (this.state.hideCompleted) {
        // If hide completed is checked, filter tasks
        query = {checked: {$ne: true}};
    }
如果我只想显示在过去30分钟内创建的todo项,即todo项在30分钟后过期,我会将查询设置为什么

我猜是这样的

if (this.state.hideExpired) {
        // If hideExpired state true, only display todo items created in the last 30 minutes.
        query = {{$ne: (currentTime - createdAt) < 30 minutes}};
    }
if(this.state.hideExpired){
//如果hideExpired state true,则仅显示在过去30分钟内创建的todo项目。
query={{$ne:(currentTime-createdAt)<30分钟};
}

非常接近,但您需要使用
$lte
$gte
而不是
$eq

if (this.state.hideExpired) {
  var now = new Date();
  var thirtyMinutesAgo = new Date() - 30 * 60 * 1000; //
  query = { createdAt: { $gte: thirtyMinutesAgo }}
}
请注意,此查询不会是被动的。这是因为
thirtimutesago
不是反应变量。如果你想让项目随着年龄的增长而动态地从列表中消失,你就需要让时间本身具有反应性。为此,我推荐这个套餐。安装该软件包后,上述代码将变为:

if (this.state.hideExpired) {
  var now = new Date();
  var thirtyMinutesAgo = Chronos.currentTime() - 30 * 60 * 1000; //
  query = { createdAt: { $gte: thirtyMinutesAgo }}
}
默认情况下,
Chronos.currentTime()
将每秒更新一次,
thirtimutesago
将是一个被动变量