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

  • Home
  • SEARCH
  • 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 9103003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:31:30+00:00 2026-06-17T01:31:30+00:00

When I sync my collection, the server returns a JSON object which I want

  • 0

When I sync my collection, the server returns a JSON object which I want to add as new models to my collection. I’ve set it up like this:

syncCollection: function() {    
        Backbone.sync('create', this,  {
          success: function (msg) {
              console.log(this);
              this.add(msg, {at: 0});

          }
    }, this);
    }

The problem is that ‘this’ doesn’t seem to point to the collection, instead it is defaulting to the global window object. I have attempted to bind this to the collection but it doesn’t seem to work:

initialize: function() {
        _.bindAll(this, 'syncCollection');
    },

How can I use .bind to ensure that this points to the collection and not the window object?

  • 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-17T01:31:31+00:00Added an answer on June 17, 2026 at 1:31 am

    Add var that = this at the beginning of the outer function(i.e. just before Backbone.sync), and replace this with that in the inner function(i.e. success).

    Note: In JavaScript this always refers to the owner of the function we’re executing, or rather, to the object that a function is a method of.

    BTW, you don’t have to use _.bindAll, _.bind is enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to sync an entire collection of models to the server in
I want sync data from iphone to the webs server. My question is how
In my project, I want to sync SQL Server Compact 3.5 with MSSQL Server
I want to create an application which will have a client and server components.
I want to override backbone.sync i have already asked this but the problem is
I've been trying to learn Backbone. I set up collection of models, each of
When you override backbone sync, both model/collection .save()/fetch() uses the same backbone sync method,
How can i sync sql server 2008-R2 (remopte server and local) using Microsoft Sync
I'm building an application in Backbone. In my collection model, I have a sync
I want to write an application that would be a custom SSH server with

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.