Meteor Clear客户订阅

shi*_*ana 2 publish-subscribe meteor

亲爱的大家,

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

其定义:

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

当我点击.ancProdCodePagination时,订阅的项目数量会持续增加10.对于分页,我想使金额保持在10,但每次点击都有不同的项目.

我该怎么办?

ric*_*ilv 5

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);
    }
});
Run Code Online (Sandbox Code Playgroud)

文档中,该stop方法执行此操作:

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