【发布时间】:2016-01-23 02:52:32
【问题描述】:
这里是场景。我有一个包含#each 循环并呈现特定模板实例的模板,根据文档在每个模板上设置数据上下文。
<template name = 'live'>
<div class = 'row'>
{{#each runways}}
<div class = 'col-md-2'>
{{> runway_panel}}
</div>
{{/each}}
</div>
</template>
这是支持它的助手:
Template.live.helpers({
runways: function(){
return Runway_Data.find();
}
});
这行得通,我的问题如下。每个 live_event_log 实例都有一个模板级订阅,该订阅订阅一个发布,该发布采用数据上下文的 _id 参数,如下所示:
Template.runway_panel.onCreated(function(){
var instance = this;
instance.autorun(function(){
var subscription = instance.subscribe('runway_status', this.data._id);
});
instance.status = function(){
return Runway_Status.find();
}
});
这是出版物:
Meteor.publish('runway_status', function(runway){
if(this.userId){
//Retrieve the last know status for the given runway
return Runway_Status.find({runway: runway});
}
});
这一切都崩溃了,我在浏览器控制台上得到了这个:
[Log] Exception in queued task: http://localhost:3000/client/views/live/runway_panel.js?4efaac87b39527d3dfd3d65a174520f9bce3c565:4:73 (meteor.js, line 888)_withTemplateInstanceFunc@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:3476:16
http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:1864:54
_withCurrentView@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2197:16
一旦我注释掉订阅行,其他一切正常,我是否在这里遗漏了一些非常明显的东西?是否与多次订阅同一出版物有关?
谢谢! :)
解决方案
感谢 Jeremy S. 的投入和夜班后的一些睡眠,我终于在没有自动运行的情况下弄清楚了。所以这里是为了后代:
Template.runway_panel.onCreated(function(){
var self = this;
self.subscribe('runway_status', this.data._id);
});
应该先睡一会再试!
【问题讨论】:
-
你能给我们原始的控制台错误吗?不是日志。您可能需要添加检查
if (this.data._id) -
我已经尝试过了,但我得到了同样的错误,data._id 肯定存在,因为如果我在订阅之前将它打印到日志中,它总是存在的。好像和烈焰有关系。我为我的无知道歉,但你原来的错误是什么意思?我发布的就是我在控制台上得到的所有内容(至少是其中的一部分,日志条目会永远存在)。
标签: javascript html meteor meteor-blaze