Skip to content

@derickbailey /1-routing-delete.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
don't route commands and events
SomeModel = Backbone.Model.extend({});
SomeCollection = Backbone.Collection.extend({
model: SomeModel
});
SomeView = Backbone.view.extend({
el: "#some-model",
template: "#some-template",
render: function(){
var html = $(this.template).tmpl(this.model);
$(this.el).html(html);
}
});
SomeRouter = Backbone.Router.extend({
routes: {
'#/delete/:id': 'delete'
},
delete: function(id){
model = someCollection.find(id);
model.destroy();
$("#some-model").remove();
}
});
<div id="some-model">
<p>display some data from the model, here</p>
<a class="delete" href="#/delete/1">delete</a>
</div>
SomeModel = Backbone.Model.extend({});
SomeCollection = Backbone.Collection.extend({
model: SomeModel
});
SomeView = Backbone.view.extend({
el: "#some-model",
template: "#some-template",
events: {
"click a.delete": "delete"
},
render: function(){
var html = $(this.template).tmpl(this.model);
$(this.el).html(html);
},
delete: function(e){
e.preventDefault();
this.model.destroy();
this.remove();
}
});
<div id="some-model">
<p>display some data from the model, here</p>
<a class="delete" href="#">delete</a>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.