Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Initialize View With Collection Backbone

 var myContentView = Backbone.View.extend({
el: "#myContent",
initialize: function()
{
this.$el.html(this.collection.models[0].get("name"));
}
 })
var Person = Backbone.Model.extend({
  defaults:{
    name:"John Smith"
  }
 }); 
 var Persons = Backbone.Collection.extend({
model: Person
 });
var person1 = new Person({name:"Jim Smith"});
var personsCollection = new Persons();
personsCollection.add([person1]);
const myCV = new myContentView({collection: personsCollection});
 
PREVIOUS NEXT
Tagged: #Initialize #View #With #Collection #Backbone
ADD COMMENT
Topic
Name
6+6 =