【问题标题】:Iron Router: My Subscription Doesn't Work Inside waitOnIron Router:我的订阅在 waitOn 中不起作用
【发布时间】:2014-10-01 20:34:19
【问题描述】:

我有一个在 Iron Router 中运行的简单订阅。

@route 'AdminEditor',
  path: '/admin/editor/:id?'
  controller: 'AdminController'
  template: 'AdminRoot'
  yieldTemplates:
    'AdminEditor': { to: 'adminAside' }

  waitOn: ->
    return Meteor.subscribe 'getArticle', @params.id

出版物:

Meteor.publish 'getArticle', (id) ->
  return Articles.find { 'id': id }

我的数据库不是空的,里面只有一个文档:

db.articles.find().pretty()
{
  "authors" : [
    "dqbxgrxzehXXTbFgG"
  ],
  "date" : ISODate("2014-10-01T20:07:48.846Z"),
  "title" : "Meteor #5",
  "content" : "hello",
  "id" : 1,
  "_id" : "WL7ygMw2jL9WnmRYZ"
}

但是当我转到 /admin/editor/1 并输入我的 chrome 调试器 Articles.findOne() 时,它不会返回任何内容。我还在 lib 文件夹中定义了该集合:

@Articles = new Meteor.Collection 'articles'  # run on both client and server

我知道我可能忘记了一件小事,但订阅似乎有效:当我从 chrome 调试器订阅它并进行查找时,它会返回对象。

Meteor.subscribe('getArticle', 1);
Articles.findOne();

【问题讨论】:

  • 您可以在waitOn 中记录@params.id 的值以检查您实际发送的内容吗?可能是您将其作为字符串而不是整数发送(就像您在控制台中一样)。
  • 就是这样!添加一个答案,以便我可以解决此问题。 :)

标签: meteor iron-router


【解决方案1】:

您可以在 waitOn 中记录 @params.id 的值以检查您实际发送的内容吗?可能是您将其作为字符串而不是整数发送(就像您在控制台中一样)。如果是这样,您只需要parseInt 就可以了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-12
    • 2014-03-17
    • 2013-11-03
    • 2023-03-20
    相关资源
    最近更新 更多