我有一個非常簡單的模型,名爲「gameModel」,下面顯示了一個集合「gamesCollection」。當我嘗試在集合中創建新遊戲時,它會向服務器發送帖子,但該帖子中沒有數據。有沒有人知道發生了什麼事?Backbone在Http Post中創建不發送數據給服務器?
//The relevant code
var game = new gameModel();
game.gameId = id;
gamesCollection.create(game);
...........
//The Collection
define([
'jQuery',
'Underscore',
'Backbone',
'collections/common/mixin',
'models/game',
'config/restresource'
], function($, _, Backbone, collectionMixin, gameModel, restDomain){
var gamesCollection = Backbone.Collection.extend({
url: (new restDomain()).getGamesRoot(),
model: gameModel,
initialize: function(){
_.extend(this.__proto__, collectionMixin);
},
parse: function(resp, xhr) {
var games = [];
for(i=0;i<resp.length;i++){
games.push(new gameModel({gameId: resp[i].gameId}));
}
return games;
},
});
return new gamesCollection;
});
您是否重載'Backbone.sync'或設置'Collection.sync'? – rudolph9
@ rudolph9不,一切都應該默認 –
我可以通過直接在模型上調用save來保存工作,這會將遊戲ID放在URL中,但仍然希望通過列表工作 –