我遇到一個問題,它讓我的model.destroy方法在主幹中正常工作。這是我的功能model.destroy()返回sinatra後端的錯誤
deleteEvent: function(){
var self = this;
var check = confirm("Are you sure you want to remove record " + this.model.get("ticket_id"));
if (check == true){
this.model.id = this.model.get('session_id');
this.model.destroy({
wait: true,
success: function(model, response, options){
console.log(options);
console.log(response);
self.$el.remove();
},
error: function(model, xhr, response){
console.log("ERROR:");
console.log(model);
console.log(xhr);
console.log(response);
}
});
}
else return;
},
這個模型看起來是這樣的:
vkapp.EventRecordModel = Backbone.Model.extend({
urlRoot: '/user_event',
idAttribute:"_id",
defaults: {
"ticket_id": '',
"start": '',
"end": ''
},
validate: function(attrib){ //This is only called when setting values for the model, not on instantiation
if (attrib.ticket_id == null)
alert("no ticket number");
if (attrib.start == undefined)
alert("no start time");
if (attrib.end == null)
alert("no end time");
if (attrib.start > attrib.end)
alert("start can't be before the end time.");
}
});
這就是我的sinatra中的路線。
delete '/user_event/:session_id' do
user_event = ProjectTimer.get(:session_id => params[:session_id])
user_event.destroy
end
我不知道爲什麼我得到一個錯誤返回。
console.log(response)的輸出是什麼;在錯誤功能? – 2013-04-11 21:57:42
'emulateHTTP:false emulateJSON:false error:function(r){if(i)i(t,r,e); t.trigger(「error」,t,r,e);} success:function (s){if(t.wait || e.isNew())r(); if(i)i(e,s,t); if(!e.isNew())e.trigger(「sync」 ,e,s,t);} wait:true xhr:Object' – 2013-04-11 22:06:32