Reputation: 9555
Why won't this render to my html page using backbone.js
here are my scripts
<script type="text/javascript" src="/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/json2.js"></script>
<script type="text/javascript" src="/underscore.js"></script>
<script type="text/javascript" src="/backbone.min.js"></script>
<script>
(function ($) {
var ListView = Backbone.View.extend({
el: $('body'), // el attaches to existing element
events: {
'click button#add': 'addItem'
},
initialize: function () {
_.bindAll(this, 'render', 'addItem'); // every function that uses 'this' as the current object should be in here
this.counter = 0; // total number of items added thus far
this.render();
},
render: function () {
$(this.el).append("<button id='add'>Add list item</button>");
$(this.el).append("<ul></ul>");
},
addItem: function () {
this.counter++;
$('ul', this.el).append("<li>hello world" + this.counter + "</li>");
}
});
var listView = new ListView();
})(jQuery);
</script>
Upvotes: 0
Views: 158
Reputation: 10224
Please change
<script type="text/javascript" src="/Sunderscore.js"></script>
to:
<script type="text/javascript" src="/underscore.js"></script>
If that doesn't work, check if javascript libraries are in the same directory with this HTML.
Upvotes: 1
Reputation: 5688
Assuming that your underscore declaration script is right in the project you are testing, I'd say you got the el declarations wrong:
el: 'body',
then you access it (assuming you use jQuery using $el and not el.
Upvotes: 0
Reputation: 516
you seem to have a typo in
<script type="text/javascript" src="/Sunderscore.js"></script>
Didn't you mean
<script type="text/javascript" src="/underscore.js"></script>
? (underscore.js in stead of Sunderscore.js)
Upvotes: 0