Defined two meteor local collections and helpers exactly the same. One helper works. The other doesn't -
i create these 2 local collections (the code written 1 after other below):
shoppingcartcollection = new meteor.collection(null); currentpricescollection = new meteor.collection(null); inside template.mytemplate.rendered add together initial info these collections (again, code 1 after other):
shoppingcartcollection.insert({"sqft" : "not yet entered"}); currentpricescollection.insert({"hdrphotos" : 100}); i've got these 2 global helpers in helpers.js (defined 1 after other)
handlebars.registerhelper("shoppingcart", function() { homecoming shoppingcartcollection.findone(); }); handlebars.registerhelper("currentprice", function() { homecoming currentpricescollection.findone(); }); when load page run these commands in console:
> shoppingcartcollection.findone(); object {sqft: "not yet entered", _id: "xcnmqjvmqqd5j7wwn"} > currentpricescollection.findone(); object {hdrphotos: 100, _id: "lp38e3mzgzuyjvsec"} in template utilize these helpers, but...
{{currentprice.hdrphotos}} //displays nil {{shoppingcart.sqft}} //displays "not yet entered" how... what... ? how can be? there kind of gotchas missing? kind of dependency or load order i'm not aware of?
the code posted working fine here.
suggest comparing code exact details of doing. also, other problems, typos, etc.
below exact test procedure used:
from nothing, @ linux console:
meteor create sodebug
note produce files "hello world" type program.
check version:
meteor --version release 0.8.1.1 edit sodebug/sodebug.js:
if (meteor.isclient) { // code autogenerated meteor create template.hello.greeting = function () { homecoming "welcome sodebug."; }; template.hello.events({ 'click input': function () { // template data, if any, available in 'this' if (typeof console !== 'undefined') console.log("you pressed button"); } }); // add together code here shoppingcartcollection = new meteor.collection(null); currentpricescollection = new meteor.collection(null); shoppingcartcollection.insert({"sqft" : "not yet entered"}); currentpricescollection.insert({"hdrphotos" : 100}); handlebars.registerhelper("shoppingcart", function() { homecoming shoppingcartcollection.findone(); }); handlebars.registerhelper("currentprice", function() { homecoming currentpricescollection.findone(); }); } if (meteor.isserver) { meteor.startup(function () { // code run on server @ startup }); } edit sodebug.html:
<head> <title>sodebug</title> </head> <body> {{> hello}} {{> t1 }} {{> t2 }} </body> <template name="t1"> <p> {{shoppingcart.sqft}} </p> </template> <template name="t2"> <p> {{currentprice.hdrphotos}} </p> </template> <template name="hello"> <h1>hello world!</h1> {{greeting}} <input type="button" value="click" /> </template> run: meteor run
manual tests:
fire chromium browser @ localhost:3000
check web browser console collections data. pass
check web browser screen templates data. pass
reorder templates in sodebug.html file, check web browser screen. pass
meteor
No comments:
Post a Comment