Skip to content

Instantly share code, notes, and snippets.

@prufrock
Last active December 26, 2015 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prufrock/7143831 to your computer and use it in GitHub Desktop.
Save prufrock/7143831 to your computer and use it in GitHub Desktop.
Made an example to show how to bind views to dom events.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.io/backbone/backbone-min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<section id="binapp">
<header id="header">
<h1>BinApp</h1>
</header>
<section id="main">
<input id="clickme" type="button" value="Click Me">
</section>
</section>
</body>
</html>
var BinApp = BinApp || {};
BinApp.AppView = Backbone.View.extend({
el: '#binapp',
// The events in the events map can only be listened
// to if they are triggered from elements that are children
// of the el element.
events: {
'click #clickme': 'handleClickMe'
},
initialize: function() {
this.clickme = this.$('#clickme');
console.log('init');
},
handleClickMe: function(){
console.log('handleClickMe');
}
});
$(function() {
new BinApp.AppView();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment