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

The Archive Base Latest Questions

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

When a fetch is called (in response to a user’s action) after an initial

  • 0

When a fetch is called (in response to a user’s action) after an initial fetch, many of the newly fetched models can be similar to the existing models from the initial fetch. If I call fetch with the add: true option, there can be duplicate models in the collection.

Problem: Instead of removing all existing models (say with id=1,2,3,4) from the collection and inserting the newly fetched models (id=1,2,3,5), is it possible to do the following 2 operations:

  1. Add only the new models id=5, resulting in a collection with id=1,2,3,4,5. Then render only the new Views (id=5)

  2. Add the new models id=5 and remove the models not found in the new fetch (id=4). Then render the new Views (id=5) and remove the old Views (id=4)

Attempt:

Instead of calling App.listingCollection.fetch(), the fetchNew() function is used. This works to only add the new models id=5 to the collection.

How should the rendering of the new views only (id=5) be triggered without re-rendering the existing views id=1,2,3,4? I tried this with the line new ListingMarkerView({ model:item }).render(); within ListingCollection, but I get an error responding to the line var marker = L.marker([this.model.get('lat'), this.model.get('lng')]); in ListingMarkerView :

Error

Uncaught TypeError: Object #<Object> has no method 'get' 

Collection

ListingCollection = Backbone.Collection.extend({
    model: Listing,
    url: '/api/search_by_bounds',

    fetchNew: function(options) {
        options = options || {};
        var collection = this,
            success = options.success;
        options.success = function(resp, status, xhr) {
            _(collection.parse(resp, xhr)).each(function(item) {
                // added this conditional block
                if (!collection.get(item.id)) {
                    collection.add(item, {silent:true});
                    new ListingMarkerView({ model:item }).render();
                }
            });
            if (!options.silent) {
                collection.trigger('reset', collection, options);
            }
            if (success) success(collection, resp);
        };
        return (this.sync || Backbone.sync).call(this, 'read', this, options);
    }
});

View

ListingMarkerView = Backbone.View.extend({

    render: function() {
        var marker = L.marker([this.model.get('lat'), this.model.get('lng')]);
        markers.addLayer(marker);
    },

    close: function() {
        this.unbind;
    }

});
  • 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-12T18:30:20+00:00Added an answer on June 12, 2026 at 6:30 pm

    A restful API has no concept of state of the clients it’s speaking to, therefore when making a GET request to retrieve a list of objects (e.g. http://example.com/restapi/user/), the rest server should ALWAYS return a full list of the matching objects.

    On the Backbone end, you should then just .reset your collection with the list from the server. .reset will empty the collection and then add all the items, like:

    my_collection.fetch({success: function(collection, resp){ 
        collection.reset(resp, {silent: true});
    }});
    

    This way you don’t get collisions and you don’t have to worry about anything. Except if you’ve got models you’ve changed in the collection locally that haven’t been saved back to the server.

    If you’re looking for a way to prevent modification of local items within a collection, that will need something like the sorcery you’re speaking of above.

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

Sidebar

Related Questions

Lets say in an application you have an entity called User. Each User can
Using RhinoMocks - can I fetch the parameters of a called function? I mean;
I have a custom report called my-newsletters in Google analytics. I want to fetch
I have some NSDictionary objects stored in an NSArray called telephoneArray . I fetch
So I have a service clint class that has a method called fetch. I
When I create a new collection, fetch is called automatically once. This gives me
I'm playing with facebook's javascript sdk and can't get the user email address to
I have a page called category.php5 that uses $_GET[category] to fetch the right content
I have a Perl script that uses Selenium to fetch a HTML document called
Smarty Templating for php lets your write output filters that are called everytime fetch()

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.