Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Backbone Collection Example

/*you must specify collection: in the parameter, you cannot use another in place of this.collection */


     var Person = Backbone.Model.extend({});
var PersonsCollection = Backbone.Collection.extend({});
        var ViewDemo = Backbone.View.extend({  
           el: $('#myContent'),  
        template: _.template("<b> <%= name %></b>"),  
              initialize: function(){  
                 this.render();  
              },  
              render: function(){  

for(var i =0; i<this.collection.models.length; i++)
{
                 this.$el.append(this.template( this.collection.models[i].toJSON()));  
 
                           }
                                        }  
        });  
const personscollection = new PersonsCollection();
personscollection.add([{name:"This is my name 1"}])
personscollection.add([{name:"This is my name 2"}])
personscollection.add([{name:"This is my name 3"}])
personscollection.add([{name:"This is my name 4"}])
Source by # #
 
PREVIOUS NEXT
Tagged: #Backbone #Collection #Example
ADD COMMENT
Topic
Name
3+5 =