我在让我的 model.destroy 方法在主干中正常工作时遇到问题。这是我的功能
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
我不确定为什么会收到错误返回。