I have:
NotificationModel = App.BB.Model.extend({
defaults : {
read : false
},
urlRoot : '/notifications'
});
NotificationCollection = App.BB.Collection.extend({
model: NotificationModel,
url: '/notifications',
initialize : function() {
this.fetch();
},
});
NotificationView = App.BB.View.extend({
tagName : 'li',
render : function() {
console.log((this.model.toJSON())
}
});
This log is not returning the items fetched from the server. But when I do me.collection.length I do get the correct length. What am I doing wrong?
Thanks
The comments others have made are making reference to the
fetchmethod being asynchronous. Sothis.fetch()returns immediately. If you are rendering your view immediately after this.fetch, the collection will still be empty.You should put something like this in the view that renders your collection: