javascript - Defining array of values in Collection in Meteor -
i have defined following collection in application:
projects = new mongo.collection("projects")
in collection, have inserted:
projects.insert({ source: "https://upload.wikimedia.org/wikipedia/commons/7/7f/pug_portrait.jpg", title: "pug", artist: "pug", description: "this piece shows duality of pug", price: "priceless" }); projects.insert({ source: "http://i.stack.imgur.com/d2abd.gif", title: "doge", artist: "doge", description: "much doge, many deal it, wow", price: "bout tree fiddy" })
i attempting create array of sources of images using following helper function:
sourcearray : function () { // returns array of sources var sources = []; (var = 0; < projects.find().count(); i++) { sources.push(images[i].source); } return sources; }
the "images variable defined as: images = projects.find().fetch();
i call helper function in html.
<p>{{sourcearray}}</p>
on page, first source appears fleetingly, disappears within few seconds. in browser console following shown:
meteor.js:888 exception in template helper: typeerror: cannot read property 'source' of undefined @ object.template.body.helpers.sourcearray (http://localhost:3000/art.js?913b8578eb54cde21abc07c994f6b29267232bc5:61:28) @ http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2880:16 @ http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:1651:16 @ http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2928:66 @ function.template._withtemplateinstancefunc (http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:3476:12) @ http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2927:27 @ spacebars.call (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:172:18) @ spacebars.mustacheimpl (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:109:25) @ object.spacebars.mustache (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:113:39) @ null._render (http://localhost:3000/template.art.js?30aa5e2d0b6d3de2f69b7341296ae51b8ce737ba:27:22)
the exception refers line of code:
sources.push(images[i].source);
how can fixed?
try:
sourcearray : function () { var images = projects.find().fetch(); var sources = []; (var = 0; < images.length; i++) { sources.push(images[i].source); } return sources; }
if said, defined images template helper property, may need
this.images[i].source
Comments
Post a Comment