我正在尝试对 Backbone 中的模型视图执行 DELETE 请求。但是,当单击链接时,Backbone 正在执行 GET 请求。如何强制模型视图破坏模型而不是获取它?
翡翠/HTML
script(type="text/template", id="allContactsTemplate").
<td><%= first_name %></td>
<td><%= last_name %></td>
<td><%= email %></td>
<td><%= description %></td>
<td><a href="contacts/<%= _id %>" class="delete">Delete</a></td>
骨干JS
// Single Contact View
App.Views.Contact = Backbone.View.extend({
tagName: 'tr',
template: template('allContactsTemplate'),
events: {
'click .delete': 'deleteContact'
},
initialize: function() {
this.model.on( 'destroy', this.unrender, this);
},
render: function() {
var template = this.template( this.model.toJSON() );
this.$el.html( template );
return this;
},
deleteContact: function() {
this.model.destroy();
},
unrender: function() {
this.remove();
}
});