0
score
이라는 모델과 scores
이라는 컬렉션이 있습니다. 그러나 모델은 부모 컬렉션의 localStorage
속성 (또는 모든 속성)을 상속하지 않는 것 같습니다. 내가 여기서 뭔가를 놓치고 있니?Backbone.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;
});
컬렉션을 score.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
@svetoslavnedkov 문제는 모델에서 선언하지 않으면 localStorage가 작동하지 않는다는 것입니다. 그것은해야하지만, 그렇지 않습니다. – mushroom
작동하지 않는 코드를 게시 할 수 있습니까? – snedkov