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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:56:54+00:00 2026-06-03T22:56:54+00:00

I have a Backbone collection and when I add a new model to it

  • 0

I have a Backbone collection and when I add a new model to it the “add” event doesn’t seem to work as I’d expect. I’ve bound 2 views to listen for add events on the collection, but only one seems to get notified of the event, and when this happens, no PUT request is sent to my server. When I remove the second bind, the other one works and the PUT request is sent. Here’s the code snippets:

    var FlagList = Backbone.Collection.extend({
    model: Flag  // model not shown here... let me know if it would help to see
});

    var FlagCollectionView = Backbone.View.extend({
    el: $('ul.#flags'),
    initialize: function() {
        flags.bind('add', this.addFlag, this);  // this one doesn't fire!!
    },
    addFlag: function(flag) {
        alert("got it 1");  // I never see this popup
    }
});

    var AddFlagView = Backbone.View.extend({
    el: $("#addFlagPopup"),
    events: {
        "click #addFlag": "addFlag"
    },
            initialize: function() {
                    flags.bind('add', this.closePopup, this);   // this one fires!!
            }
    addFlag: function() {
        flags.create(new Flag);
    },
    closePopup: function() {
        alert("got it 2");  // I see this popup
    }
});

var flags = new FlagList;
var addFlagView = new AddFlagView;
var flagCollectionView = new FlagCollectionView;
  • 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-03T22:56:56+00:00Added an answer on June 3, 2026 at 10:56 pm

    This code works for me:

    var FlagList = Backbone.Collection.extend({});
    
    var FlagCollectionView = Backbone.View.extend({
      initialize: function() {
        flags.bind('add', this.addFlag, this); 
      },
      addFlag: function(flag) {
          alert("got it 1");
      }
    });
    
    var AddFlagView = Backbone.View.extend({
      initialize: function() {
        flags.bind('add', this.closePopup, this);
      },
      closePopup: function() {
        alert("got it 2");
      }
    });
    
    var flags = new FlagList;
    var addFlagView = new AddFlagView;
    var flagCollectionView = new FlagCollectionView;
    
    flags.add({key:"value"});
    

    check the jsFiddle

    Your problem is somewhere else.

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

Sidebar

Related Questions

I have the following Backbone.js model and collection: // Model lr.Event = Backbone.Model.extend({}); //
I have the following collection: UsersMod.users_list = Backbone.Collection.extend({ add : function(model) { var duplicate
I have a Backbone View that has a Collection as its Model. If the
I have a view and collection like this: window.DmnView = Backbone.View.extend({ template: _.template($(#tmpl_dmnListItem).html()), events:
I have very simple backbone model and collection. I have a corresponding backbone.marionette.CollectionView and
I have a backbone collection and when I remove a model from the collection,
let's say I have : var Book = Backbone.Model.extend(); var Collection = Backbone.Collection.extend({ model:
I have a Backbone.js Collection and I have an array of model IDs that
I'm using codebrew\backbone-rails in a nested model example (say I have a collection of
I have a Backbone.Model named Company . My Company model has an Employees Backbone.Collection

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.