0
새로운 백본 모델 (Knockback 내에서 작업)을 만들고 있으며 현재 RESTful 백엔드 서버로 설정하려고합니다. 문제는 targets.sync()를 사용할 때 URL이 허용되지 않는다는 것입니다. 그러나 targets.fetch()를 수행 할 때 정상적으로 작동하고 지정된 URL에서 데이터를 올바르게 가져옵니다. 여기서 내가 뭘 잘못하고 있니? Backbone.js 모델 동기화 클레임 URL Undefined
/**
* Objectives model
*/
var Objective = Backbone.Model.extend({
url: 'api/objective',
// Defaults
defaults: {
category: null,
weight: null,
name: null,
descriptor: null
}
});
/**
* Basic objectives collection
*/
var ObjectiveCollection = Backbone.Collection.extend({
model: Objective,
url: function() {
return "api/objective";
},
initialize: function(models,options) {}
});
코드
실제로이 컬렉션의 사용은 여기에서 볼 수 있습니다 만들려면 :var objectives = new ObjectiveCollection();
objectives.fetch();
var view_model = {
objectives: kb.collectionObservable(objectives, {view_model: kb.ViewModel})
};
ko.applyBindings(view_model, $('#objectives').get(0));
// Listener for the click button
$('#click').click(function() {
counter++;
var objective_model = new Objective({name: Math.random(), descriptor: 'What up'});
objectives.add(objective_model);
objectives.sync();
});/**/
알아두면 좋을 것 같습니다. 해명 해줘서 고마워! – moberemk