After searching various resources for solutions to my issue, I stumbled upon this helpful and . Both of these links provided valuable insights.
The issue I'm facing is that one of my templates is loading twice - first with the collection undefined, and then again with the collection defined. This results in the following output in the console:
TRADEID
undefined
TRADEID
L…n.Cursor {collection: LocalCollection, sorter: null, matcher: M…o.Matcher, _selectorId: undefined, skip: undefined…}
In an attempt to resolve this problem, I have implemented guarding in my JavaScript file as shown below:
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;
}
});
Then, in my template, I attempt to display the borrowed element:
<h2 class="no-margins">{{borrow.element}}</h2>
<small>Borrow</small>
However, the template always renders blank - there is no text displayed. I suspect that the collection is not available during the initial rendering of the template, and it fails to update once the collection becomes available.
Thank you for any assistance you can provide!