The event hash in the view is used to bind events from the DOM to your view, for example. events raised by elements in your visualized view. To listen to the events created by your collection, you will need to set them manually:
var ContactsView = Backbone.View.extend({ initialize: function(){ contacts.on("collection:init",this.populate,this); } ... });
Note that you use the global contact variable, I would advise you to use the Backbone mechanisms and pass your collection to the constructor, as you do with el:
var ContactsView = Backbone.View.extend({ initialize: function(){ console.log(this.collection.models); this.collection.on("collection:init",this.populate,this); } ... }); var contacts_view = new ContactsView({ el: $('#view-contacts'), collection:contacts });
As noted in the @mu comments in the comments, your event will not do anything, since you fire it in the collection initialization method, which is automatically called by the collection constructor, so before you can link something into the view. See this script to visualize the order of calls: http://jsfiddle.net/yRuCN/
Run it elsewhere, or if I read your intentions correctly, you (probably) want to use the built-in reset event:
var ContactsView = Backbone.View.extend({ initialize: function(){ this.collection.on("reset",this.populate,this); } ... });
See http://jsfiddle.net/yRuCN/1/ for an example of potential uses.
source share