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 8527249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:30:12+00:00 2026-06-11T08:30:12+00:00

I wish to read a whole database table to fill a Backbone.js Collection ,

  • 0

I wish to read a whole database table to fill a Backbone.js Collection, before updating a View.

I am using fetch and listening to the reset event.

My problem is the reset event fires up before the http request is made to the server.

My question is: how can I render the view AFTER the data is received back from the server on a fetch?

Here is a jsfiddle showing the problem (with a debugger placed at reset):

http://jsfiddle.net/GhaPF/16/

The code:

$(document).ready(function() {

    var Item = Backbone.Model.extend({
        urlRoot : './items'
    });

    var ItemList = Backbone.Collection.extend({
        model: Item,
        url: './items/',
    });


    var ItemListView = Backbone.View.extend({
        el: 'body',
        initialize: function(myitemList) {
            this.itemlist = myitemList;
            this.itemlist.bind('reset', this.debuggThis());
        },
        debuggThis: function() {
            debugger;
        },
        render: function() {

        },
        events: {
            "keypress #new-item":  "createOnEnter"
        },
        createOnEnter: function(e) {
        }
    });

    $("#new-item").focus();
    var itemlist = new ItemList();
    var myitemListView = new ItemListView(itemlist);
    itemlist.fetch();
});​

The following code works, but it just doesn’t feel like proper backbone.js (MVC) code since it would be placed outside of the View definition:

itemlist.fetch().complete(function(){
  • 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-11T08:30:14+00:00Added an answer on June 11, 2026 at 8:30 am

    Maybe the issue is this line:

    this.itemlist.bind('reset', this.debuggThis());
    

    Should actually be:

    this.itemlist.bind('reset', this.debuggThis);
    

    Your debugThis function was getting run at the time you set up the listener for the ‘reset’ event – not when the event is triggered. This was telling JavaScript that you wanted debugThis to return a callback function instead of having debugThis “be” the callback function.

    Also, orangewarp’s comment about passing ‘this’ as the third parameter is probably relevant too. Sot it would end up as:

    this.itemlist.bind('reset', this.debuggThis, this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Icefaces for webapplication development. I wish to read a file from
I have a SQLite database that I wish to read records from and execute
I have a binary file I wish to read for my android app. the
I wish to do this using only XAML - How to add an additional
I wish fetch data in a XML file, where Tag is a variable.. My
I wish I could figure this out. I need to produce a table with
I am trying to read from a file using fgets and sscanf. In my
HOW I WISH I HAD PHRASED MY QUESTION TO BEGIN WITH Take a table
I wish to read from cin in C++ from the current position up until
I wish to process files (.krn-files that can be read as txtfiles) and replace

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.