简体   繁体   English

流星发布/订阅无效

[英]Meteor pub/sub not working

Here is my route that triggers the subscribe 这是我触发订阅的路线

   Router.route('listView', {
        path: '/',
        template: 'listViewTemplate',
        waitOn: function(){
            Meteor.subscribe('lists');
        }
    });

My publish method 我的发布方式

Meteor.publish('lists', function(){
     return listCollection.find();
});

And the template that renders them to the view 以及将它们呈现给视图的模板

    <template name='listViewTemplate'>
        <ul class='listViewList'>
            <li class='listViewEntry'>
                {{#each listCollection}}
                    <b>{{title}}</b>, {{description}}
                {{/each}}
            </li>
        </ul>
    </template>

When I enter a record through the command line, nothing happens, but collection.find().fetch() ensures that they are being persisted. 当我通过命令行输入记录时,什么也没发生,但是collection.find().fetch()确保它们被持久保存。

I hope you've added a helper too: 我希望您也添加了一个助手:

Template.listViewTemplate.helpers({
    listCollection: function() {
        return listCollection.find();
    }
});

Also don't forget to return a value on your waitOn : 同样不要忘记在waitOn上返回一个值:

waitOn: function(){
   return Meteor.subscribe('lists');
}

When using waitOn you also need a loadingTemplate 使用waitOn您还需要一个loadingTemplate

<template name="loading">Loading</template>

and also add the loadingTemplate definition into the route: 并将loadingTemplate定义添加到路由中:

Router.route('listView', {
    path: '/',
    template: 'listViewTemplate',
    waitOn: function(){
        return Meteor.subscribe('lists');
    },
    loadingTemplate: 'loading'
});

If you get a blank screen or something instead it might be worth looking at the Javascript error log in your browser to see where the issue is. 如果出现黑屏或其他问题,可能值得在浏览器中查看Javascript错误日志以查看问题所在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM