我正在學習BackboneJS。在下面的代碼this.at(0).destroy();
:用REST後端我想發出一個HTTP一致DELETEBackboneJS:REST DELETE不會觸發destroy()
var Task = Backbone.Model.extend({
defaults: {
name: 'Testing Just',
},
url: 'http://localhost:8080/todos/',
});
var Tasks = Backbone.Collection.extend({
model: Task,
url: 'http://localhost:8080/todos/'
});
var tasks = new Tasks();
tasks.fetch({
context: tasks
}).done(function() {
console.log("Tasks:" + this.length)
console.log(this.at(0).get('name'));
this.at(0).destroy();
console.log("Tasks:" + this.length);
console.log(this.at(0).get('name'));
});
該模型是從集合中刪除,但沒有休息DELETE發生到後端。 REST後端的刪除與'localhost:8080/todos/0'一起使用。 請告訴我缺少的東西。
您的模型有ID嗎? –