Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

don't route commands and events

View 1-routing-delete.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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();
}
});
View 1-routing-delete.js
1 2 3 4
<div id="some-model">
<p>display some data from the model, here</p>
<a class="delete" href="#/delete/1">delete</a>
</div>
View 1-routing-delete.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
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();
}
});
View 1-routing-delete.js
1 2 3 4
<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.