【发布时间】:2015-03-14 13:15:45
【问题描述】:
出于某种奇怪的原因,Backbone 试图放置我的模型对象而不是将其发布到服务器。
该错误是 HTTP 500 错误,因为 Backbone 试图放置一个没有 id 的模型(因为我已将其设为未定义):
PUT /api/teams/undefined 500 285ms - 135b
这是我的代码:
this.model.id = undefined;
this.model._id = undefined;
teamCollection.add(this.model);
this.model.save(null,
{
success: function (model) {
$('.top-right').notify({
message: {text: ' New team added! '},
type: 'info',
fadeOut: {
delay: 3500
}
}).show();
window.userHomeMainTableView.render();
}
,
error: function (model) {
teamCollection.remove(model);
$('.top-right').notify({
message: {text: ' Error adding team :( '},
type: 'danger',
fadeOut: {
delay: 3500
}
}).show();
}
});
即使在“强制”未定义 model.id 和 model._id 之后,Backbone 仍会尝试执行 HTTP PUT。这怎么可能?
【问题讨论】: