【问题标题】:How to find data inserted in meteor collection?如何查找流星集合中插入的数据?
【发布时间】:2016-06-19 17:52:33
【问题描述】:

我在客户端订阅了收藏。在集合上的新插入之后,只是重定向到该插入集合的查看页面。

在服务器上使用“postDetail”集合发布

Meteor.publish('postDetail', (postId: string) => {
    return PostCollection.find({ _id: postId });
});

插入页面:

collection.insert(this.currentPost, (error, postId) => {

            if (postId) {
                this.router.navigate(['detail', { postId: postId }]);
            }
            else {

            }
        });

在查看页面:

 this.subscribe('postDetail', this.postId, () => {
    collection.findOne({ _id: this.postId}); 
    **// this is not giving the inserted data at first time**
  });

【问题讨论】:

  • 我认为你需要更清楚你的实际问题是什么。该主题的问题非常广泛,最好通过阅读手册来回答。你的实际问题是什么?
  • 在插入成功回调时重定向但没有在下一页获取数据。

标签: meteor publish-subscribe


【解决方案1】:

查看您的订阅,您正在使用 this.subscribe(),它看起来像一个模板级别的订阅。当模板被销毁(不再呈现)时,此订阅将被删除。

因此,如果您在插入后重新路由到不同的模板,您也需要重新订阅该模板。

(Meteor 足够聪明,可以在两次订阅之间保留缓存的数据,所以第二次订阅会很快。但你还是要这么做)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多