【问题标题】:Meteor collection query with current timestamp具有当前时间戳的流星集合查询
【发布时间】:2013-01-16 03:11:42
【问题描述】:

我需要安排具有 'scheduledAt 属性和时间戳的项目,包括当前的和预计的。不幸的是,参考日期只计算一次。

如何解决?

Items.find({scheduledAt : {$lt : new Date()}}).observe(...)

【问题讨论】:

  • 传递“new Date()”将传递日期对象的 toString(),这可能不是你想要的。尝试传递“+new Date()”以将其转换为实际时间戳。

标签: date collections find meteor


【解决方案1】:

因为 Meteor 是一个单页应用程序,所以“new Date()”不会被调用,除非您通过执行以下操作使其具有响应性:

函数 findItems() { 会话.get Items.find({scheduledAt : {$lt : new Date()}}).observe(...) }

你可以通过做触发 Session.set('triggerEvent');

如果您只想定期执行此操作,请使用 Meteor.setTimeout()

【讨论】:

    猜你喜欢
    • 2020-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    • 2016-08-28
    相关资源
    最近更新 更多