Meteor以反应方式订阅服务器

时间:2015-07-03 06:09:47

标签: javascript meteor

我似乎无法使用以下代码从服务器端获得响应式集合更改:

Template.name.onRendered(function() {
    this.autorun(function(){
            Meteor.subscribe("items", Session.get("start"), Session.get("end"), function () {
             //update UI
            });
    });
});

Session.get("start")更改时,它会正确地订阅服务器范围内的所有项目,但如果我从mongo shell中删除项目,则不会调用订阅回调,即重新订阅不是在客户端触发,我需要让这两个条件有效,

  1. 当Session.get(" start"),Session.get(" end")改变了然后得到了 服务器范围内的数据(我使用订阅执行此操作)和更新UI
  2. 当查询结果Items.find(start,end)发生变化时(服务器端更改为集合)那么也会更新UI
  3. 我几乎可以使用另一个自动运行来跟踪Items.find()查询,

        Template.name.onRendered(function() {
            // when user changed the date range, get the new data
            this.autorun(function(){
                    Meteor.subscribe("items", Session.get("start"), Session.get("end"), function () {
                     //update UI
                    });
            });
            // get all the changes from server and update UI
            this.autorun(function(){
                   Items.find(start, end);
                   //update UI   
            });
        });
    

    但似乎在每次订阅完成后,查询自动运行也会运行,这不是必需的,它真的应该只从服务器中选择更改,我该怎么做以反映服务器端范围内的任何更改客户端?

0 个答案:

没有答案