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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:38:58+00:00 2026-06-14T18:38:58+00:00

collection and view in back bone var studentmodel = Backbone.Model.extend(); var studentcollection = Backbone.Collection.extend({

  • 0

collection and view in back bone

var studentmodel = Backbone.Model.extend();

    var studentcollection = Backbone.Collection.extend({
model : studentmodel,
url : 'http://localhost/bb/data.JSON',
parse : function(response){
    //console.log(response.data);
    return response.data;
    //return response;
},
  });



var studentlistview = Backbone.View.extend({
    tagName : "ul",
    className : "studentlistul",
    initialize : function(){
        this.model.bind("reset", this.checkEvent,this);
        this.model.bind("add", this.checkEvent,this);
    },
      checkEvent : function(){

        $(this.el).html("");

    _.each(this.model.models, function(student){

    $(this.el).append(new studentListItemView({ model : student}).render2().el);
    }, this);

    $('#studentlistdiv').html($(this.el));

    return this;

}
});

and try to add items to this model and its work, my question is that inside render fn how can i get the event type while this.model.bind(“add”, this.checkEvent,this) this evt fire. inside checkEvent how can i get the type of event ie which one fired add or reset. this is my question plz help me

  • 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-14T18:38:59+00:00Added an answer on June 14, 2026 at 6:38 pm

    There is no reliable way for a Backbone event handler to know what event triggered it. Instead of doing this:

    this.model.bind("reset", this.checkEvent, this);
    this.model.bind("add",   this.checkEvent, this);
    

    you should have separate handlers for each desired action:

    // A reset generally means that you want to redraw the whole thing.
    this.model.bind("reset", this.render, this);
    
    // If one model is added then you usually just want to render the
    // the new one.
    this.model.bind("add", this.render_one, this);
    

    and then your render would look sort of like this:

    this.$el.empty();
    this.collection.each(this.render_one, this);
    return this;
    

    A couple extra things while I’m here:

    1. Backbone views already have a jQuery version of their this.el in this.$el so there’s no need to $(this.el), just use this.$el.
    2. Backbone views handle the collection option the same way they handle model. So if you new View({ collection: c }) then the view will automatically have this.collection. If you have a collection, use collection and if you have a model, use model; using accurate names is less confusing.
    3. Backbone collections have a bunch of Underscore methods already mixed in so you can say this.collection.each(...) instead of _(this.collection.models, ...).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my Model View and Collection : window.Report = Backbone.Model.extend({}); window.ReportCollection = Backbone.Collection.extend({
Here's an example of my collection view: mod.AppListView = Backbone.View.extend({ initialize: function() { var
I have a Backbone View that has a Collection as its Model. If the
I use backbone.js and have a model without a collection. In the view I
I have the following Backbone.js model and collection: // Model lr.Event = Backbone.Model.extend({}); //
Here is what I have so far: var Item = Backbone.Model.extend({ defaults: { id:
I've got the following view file: var BucketTransferView = Backbone.View.extend( { initialize: function(args) {
I use Backbone.js to create a web app,all the view,collection and model write into
I have a view and collection like this: window.DmnView = Backbone.View.extend({ template: _.template($(#tmpl_dmnListItem).html()), events:
var ListView = Backbone.View.extend({ el: $('hello'), initialize: function() { var stuff = new FieldCollection();

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.