Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:53:28+00:00 2026-06-15T17:53:28+00:00

I am new to backbone.js and am having trouble pin pointing why my view

  • 0

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.

Gist for coupons.js and offers.js

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:53:30+00:00Added an answer on June 15, 2026 at 5:53 pm

    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 offerList is asynchronous, but you’re instantiating the collection view synchronously. That is, this in CouponCollectionView‘s constructor :

    this.collection.on('add remove', this.render, this);
    

    is getting called while the collection is still null:

    var coupons = null;
    $.getJSON('http://localhost:3000/api/coupons.json', function(response){
        coupons = new CouponCollection(response);
        app.coupons = coupons;
    });
    

    You might want to consider using var coupons = new CouponCollection(), and calling coupons.fetch() — that way, the collection will be instantiated immediately, and ready for your on call in the View.


    Set up the collection so that you can call fetch:

    var CouponCollection = Backbone.Collection.extend({
        model: Coupon,
    
        // tell Backbone where to send the "fetch" request
        url: 'http://localhost:3000/api/coupons.json'
    });
    

    Instantiate the collection immediately, and call fetch on it:

    var coupons = new CouponCollection();
    coupons.fetch();
    

    Add a reset listener to the collection (triggers when fetch is complete), and render the view in the handler:

    this.couponCollectionView = new app.CouponCollectionView({collection: this.couponList});
    var self = this;
    this.couponList.on("reset", function() {
        $('#content').empty().append(self.couponCollectionView.render().el);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to Backbone and Marionette and am having a tough time getting
I'm new to Backbone.js and working with JSON. I'm having trouble working with the
I'm new to Backbone.js and am having trouble figuring out the proper architecture for
I'm new to backbone.js and having some trouble wrapping my head around an issue
I'm having trouble with passing model data from a Backbone View to a template
I am having trouble with some really basic Backbone.js functionality. window.Album = new Backbone.Model.extend({});
I'm pretty new to backbone.js and am still learning how everything works. I'm trying
I'm pretty new to Backbone so excuse me if this question is a little
I'm new to Backbone and I'm trying to get a basic view rendered using
I'm pretty new to Backbone.js and Require.js. In my app I'm loading templates into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.