Skip to content

@derickbailey /events.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Backbone responsibilities
Backbone.View.extend({
initialize: function(){
this.model.bind("change:foo", this.render, this);
},
render: function(){
// render some HTML here
// tell any listeners it happened
this.trigger("it:happened");
}
});
Backbone.history.start();
myModel.set({someAttr: "some value"});
// ... later in the code ...
alert(myModel.get("someAttr")); // => alerts "some value"
myRouter.navigate("some/route");
// save changes to the model, back to a server
myModel.save();
// get all of the models for this collection, from a server
myCollection.fetch();
MyRouter = Backbone.Router.extend({
routes: {
"some/route": "someMethod"
},
someMethod: function(){
// do stuff here
}
});
var vent = _.extend({}, Backbone.Events);
vent.bind("foo", function(){
alert("bar");
});
// ... later in the code
vent.trigger("foo"); // => alerts "bar"
MyView = Backbone.View.extend({
events: {
"click #someElement": "someMethod"
},
someMethod: function(){
alert("you clicked it!");
},
render: function(){
$(this.el).html("<button id='someElement' value='click me'></button>");
}
});
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.