Last active
December 26, 2015 11:29
-
-
Save prufrock/7143831 to your computer and use it in GitHub Desktop.
Made an example to show how to bind views to dom events.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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