【发布时间】:2017-07-13 09:07:19
【问题描述】:
根据the docs:
如果您在响应式计算中调用 Meteor.subscribe,例如使用 Tracker.autorun,则订阅将在计算无效或停止时自动取消;
然后明确提到没有必要在autorun 中停止订阅。
流星助手也是这样吗?我相信他们算作reactive computation,但我不完全确定!
编辑
这是一个代表这种情况的sn-p代码。
那么问题来了:我需要做些什么来停止objectsSub 还是全部自动排序?
<template name ="Foo">
{{#with myContext}}
{{#each objects}}
<!--Show stuff-->
{{/each}}
{{/with}}
</template>
Template.Foo.onCreated(function(){
this.subscribe('myContextSub');
});
Template.foo.helpers({
myContext(){
return MyContextCollection.findOne();
},
objects(){
Meteor.Subscribe('objectsSub',this.someContextAttribute);
return ObjectsCollection.find({});
},
});
【问题讨论】:
-
你为什么要订阅助手?这对我来说似乎很奇怪。你能展示你的代码吗?
-
我在代码中添加了一个小sn-p。我在帮助程序中订阅的原因是有可用的数据上下文,我将能够在订阅参数中使用
-
好的,我明白你在做什么。我有几个想法,我会回答。
标签: meteor publish-subscribe meteor-blaze