First of all, I am new to Meteor and Javascript, but I am trying my best to grasp the language.
Need help with displaying live data on a home page.
in the home.html i am calling this helper “part” and passing “45” as argument
<p>Price of No. 45 is {{part 45}}</p>
in home.js I am searching the Part database for an item that match the type I specified through the passed argument then sort it and finally, i try to return its value of its price key.
Template.home.helpers({
part: function (type) {
return Part.findOne({'type':type}, { sort: { createdAt: -1 }}).price;
}
});
I am getting the following error, and I understand why because of the delay in retrieving data from the db.
Exception in template helper: TypeError: Cannot read property 'price' of undefined
What can I do to fix this? callback or something.
Thanks