1
從localStorage覆蓋的方法恢復我的集合(下例中的getLabel())不再被調用。基本方法被調用。我認爲問題是,我告訴集合使用BaseModel。但如何更改集合以使用KeywordLog和CommentLog模型?backbone.js - 從localStorage恢復後沒有模型繼承
我用下面的模型繼承:
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")
});