【发布时间】:2016-05-23 23:00:29
【问题描述】:
所以在寻找堆栈溢出以解决这个问题之后,我遇到了这个https://dweldon.silvrback.com/common-mistakes 和这个https://dweldon.silvrback.com/guards 两者都非常有用。
我的问题是我的一个模板加载了两次,一次是未定义集合,另一次是定义了集合。所以在控制台中我看到了类似的东西:
TRADEID
undefined
TRADEID
L…n.Cursor {collection: LocalCollection, sorter: null, matcher: M…o.Matcher, _selectorId: undefined, skip: undefined…}
在我试图解决这个问题的过程中,我已经实现了保护,所以我的 Js 文件看起来像这样
TRADEINFO = new Mongo.Collection("trade_info");
Template.E4E_tradeTile.onCreated(function(){
this.subscribe('users');
this.subscribe('trade_info');
});
Template.E4E_tradeTile.helpers({
borrow(){
console.log(this.tradeID);
var guard = TRADEINFO.findOne();
var query = TRADEINFO.find();
console.log(guard && query);
return guard && query;
}
});
然后在我的模板中我读出了这个借用
<h2 class="no-margins">{{borrow.element}}</h2>
<small>Borrow</small>
模板似乎总是呈现空白,(没有文本)所以我认为在呈现模板时集合不可用,然后当集合变为可用时它不会更新。
再次感谢您的帮助!
【问题讨论】:
标签: javascript mongodb meteor meteor-blaze