I am new to backbone.js and am having trouble pin pointing why my view is undefined on line 67 of coupons.js. I posted a gist as they are pretty long files.
Also, if I refresh the browser a bunch of times, eventually it works just fine and then I refresh again and it breaks and I can refresh again until it works and then again until it breaks. Painful cycle.
This error occurs when you try to call a method on an object that’s null/undefined. The issue is that your call to fetch data for
offerListis asynchronous, but you’re instantiating the collection view synchronously. That is, this inCouponCollectionView‘s constructor :is getting called while the collection is still null:
You might want to consider using
var coupons = new CouponCollection(), and callingcoupons.fetch()— that way, the collection will be instantiated immediately, and ready for youroncall in the View.Set up the collection so that you can call
fetch:Instantiate the collection immediately, and call
fetchon it:Add a
resetlistener to the collection (triggers whenfetchis complete), and render the view in the handler: