0
我從https://github.com/ccoenraets/backbone-cellar得到了這段代碼。當我嘗試使用slim.php將新模型添加到數據庫時,它顯示「錯誤嘗試添加此項目時發生錯誤」。但是,當我試圖獲取,更新,刪除它的工作良好。爲什麼它僅在添加時顯示錯誤?問題saveWine using backbone.js
引導/ JS /視圖/ winedetails.js
window.WineView = Backbone.View.extend({
initialize: function() {
this.render();
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
events: {
"click .save" : "beforeSave",
"click .delete" : "deleteWine"
},
beforeSave: function() {
var self = this;
var check = this.model.validateAll();
if (check.isValid === false) {
utils.displayValidationErrors(check.messages);
return false;
}
// Upload picture file if a new file was dropped in the drop area
if (this.pictureFile) {
this.model.set("picture", this.pictureFile.name);
utils.uploadFile(this.pictureFile,
function() {
self.saveWine();
}
);
} else {
this.saveWine();
}
return false;
},
saveWine: function() {
var self = this;
this.model.save(null, {
success: function (model) {
self.render();
app.navigate('wines/' + model.id, false);
utils.showAlert('Success!', 'Wine saved successfully', 'alert-success');
},
error: function() {
utils.showAlert('Error', 'An error occurred while trying to add this item', 'alert-error');
}
});
},
deleteWine: function() {
this.model.destroy({
success: function() {
alert('Wine deleted successfully');
window.history.back();
}
});
return false;
}
});
感謝這麼多