0
我有一個模型稱爲score
和集合稱爲scores
。但是,該模型似乎並沒有繼承父集合中的localStorage
屬性(或者就此而言,任何屬性)。我在這裏錯過了什麼嗎?Backbone.js模型不從集合繼承
運行主幹與RequireJS。
型號/ score.js
define([
'underscore',
'backbone',
'localstorage'
], function(_, Backbone, Store){
var ScoreModel = Backbone.Model.extend({
defaults: {
board_id: null,
ns_pair: null,
ew_pair: null,
ns_score: null
},
validate: function(attrs, options){
if(isNaN(attrs.board_id) || attrs.board_id < 1){
return 'Invalid Board ID!';
}
},
localStorage: new Store("ScoreCollection")
});
return ScoreModel;
});
收藏/ scores.js
define([
'underscore',
'backbone',
'models/score',
'localstorage'
], function(_, Backbone, ScoreModel, Store){
var ScoreCollection = Backbone.Collection.extend({
model: ScoreModel,
localStorage: new Store("ScoreCollection")
});
return ScoreCollection;
});
main.js
require.config({
paths: {
// Major libraries
jquery: 'libs/jquery/jquery.min',
underscore: 'libs/underscore/underscore.min',
backbone: 'libs/backbone/backbone.min',
// Require.js plugins
text: 'libs/require/text',
// Backbone.js plugins
localstorage: 'libs/backbone/localstorage',
// Just a short cut so we can put our html outside the js dir
// When you have HTML/CSS designers this aids in keeping them out of the js directory
templates: '../templates'
}
});
// Let's kick off the application
require([
'app'
], function(App){
App.initialize();
});
我看不到你的數據繼承Backbone.Collection和Backbone.Model以外的其他東西。另外我認爲你不需要在模型上聲明localStorage。 – snedkov 2013-03-09 10:21:53
@svetoslavnedkov問題是localStorage不起作用如果我沒有在我的模型中聲明它。它應該,但事實並非如此。 – mushroom 2013-03-11 09:44:18
你可以發佈不起作用的代碼嗎? – snedkov 2013-03-11 14:18:18