【问题标题】:Meteor Clear Client SubscriptionMeteor Clear 客户订阅
【发布时间】:2014-04-20 06:11:45
【问题描述】:

亲爱的,

   Template.tmp_detail_campaign_code_batch.events({
        'click .ancProdCodePagination': function (e) {
            Meteor.subscribe('ItemPage', Number*10,10)
        }
    });

它的定义:

Meteor.publish('ItemPage', function(skipItem, takeItem){
    return Item.find({},{
        skip : skipItem,
        limit : takeItem
    }); }

当我点击 .ancProdCodePagination 时,订阅项目的数量不断增加 10。对于分页,我想让数量保持在 10,但每次点击的项目不同。

我该怎么办?

【问题讨论】:

    标签: meteor publish-subscribe


    【解决方案1】:

    您只需要先stop 上一个订阅,这将涉及存储它在某处返回的句柄:

    var itemSub;
    
    Template.tmp_detail_campaign_code_batch.events({
        'click .ancProdCodePagination': function (e) {
            if (itemSub)
                itemSub.stop();
            itemSub = Meteor.subscribe('ItemPage', Number*10,10);
        }
    });
    

    the docsstop 方法执行此操作:

    取消订阅。这通常会导致服务器指示客户端从客户端的缓存中删除订阅的数据。

    【讨论】:

    • 我们怎样才能使itemSub 为客户会话持久化?在 Session 中存储itemSub 会修剪掉方法,我们不能在上面调用stop
    猜你喜欢
    • 1970-01-01
    • 2016-08-13
    • 2015-10-15
    • 2017-02-03
    • 1970-01-01
    • 2012-08-26
    • 1970-01-01
    • 1970-01-01
    • 2013-01-18
    相关资源
    最近更新 更多