Answer the question
In order to leave comments, you need to log in
Why can't I specify a collection for the view?
var Chat = Backbone.Model.extend({
messageList: new MessageList(),
messageListView: new MessageListView({collection: this.messageList}),
switchChannel: function(channel) {
this.messageList.fetch({url: 'channels/'+channel, reset: true})
}
});
// in other file
var MessageList = Backbone.Collection.extend({
model: Message,
})
var MessageListView = Backbone.View.extend({
initialize: function(){
console.log(this.collection)
this.listenTo(this.collection, 'reset', this.render);
},
Answer the question
In order to leave comments, you need to log in
In this place:
var Chat = Backbone.Model.extend({
messageList: new MessageList(),
messageListView: new MessageListView({collection: this.messageList}),
...
var Chat = Backbone.Model.extend({
initialize: function(){
this.messageList = new MessageList();
this.messageListView = new MessageListView({collection: this.messageList});
}
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question