After restoring my collection from localStorage overwritten methods (getLabel() in following example) are no longer called. The base method is called instead. I think the problem is, that I tell the collection to use the BaseModel. But how to change the collection to work with the models KeywordLog and CommentLog?
I use the following model inheritance:
var BaseLog = Backbone.Model.extend({
defaults: {
timecode: null,
color: null,
isRange: false,
},
getLabel: function() {
return 'base';
}
});
var KeywordLog = BaseLog.extend({
defaults: _.extend({}, BaseLog.prototype.defaults, {
keyword: null,
}),
getLabel: function() {
return 'keyword';
}
});
var CommentLog = BaseLog.extend({
defaults: _.extend({}, BaseLog.prototype.defaults, {
text: null,
}),
getLabel: function() {
return 'comment';
}
});
var Loglist = Backbone.Collection.extend({
// This might be the problem after restoring drom localStorage..?
model: BaseLog,
localStorage: new Store("storage")
});
Collections will only work with a single model type. I suggest you switch to a single model and include
labelas an attribute.