I tried a simple example (see the full code below) with the latest derived versions of backbone.js, underscore.js and jquery. However, I cannot display anything on the screen. I tried to record this. $ El is for the console log, and it seems that indeed html var also contains the correct parsed HTML from the test pattern. But nothing is displayed in the browser window.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>testing Backbone.js</title> </head> <body> <script type="text/template" id="test-template"> <div id="container"> <%= test %> </div> </script> <script type="text/javascript" src="js/lib/jquery.js"></script> <script type="text/javascript" src="js/lib/underscore.js"></script> <script type="text/javascript" src="js/lib/backbone.js"></script> <script type="text/javascript"> var testView = Backbone.View.extend({ el: $("#container"), template: _.template($('#test-template').html()), render: function() { var html = this.template({test: 'hello World!'}); this.$el.html(html); return this; } }); $(document).ready(function() { var test = new testView(); test.render(); }); </script> </body> </html>
source share