How to use backbone.js

User :
To declare User model :
App.Backbone.User = Backbone.Model.extend();
 To declare User Collection :
  1. we assign the model.
  2.  we bind the add and remove event to collection
 To declare User Collection :
App.Backbone.Users = Backbone.Collection.extend({ 
    model : App.User,
    initialize: function(models, args) {
       this.bind('add', this.renderone);
       this.bind('remove', this.destroy); },
        var view = new App.Backbone.UserView({model: user});
        var view = new App.Backbone.UserCardView({model: user});

To initialise the Collection    of user

App.Users = new App.Backbone.Users();
To add user in collection.
var data ={id:'rahul', username:rahul,firstname:'Rahul'}; 

//at this point automatically view will be rendered as we bind the add event in collection above.

To remove a model
// so on remove view will also remove
To update a model
var data ={id:'rahul', username:rahul,firstname:'Rahul',lastname:'mehta'};
the view also render due to change event in view.


About rahul23134654

Hi, I am Rahul Meha , B.E. in (I.T.)
This entry was posted in UI Js. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s