Hello-World
Hello-World

Reputation: 9555

backbone - why wont this render to my html page

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

Answers (3)

Hui Zheng
Hui Zheng

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

ChuckE
ChuckE

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

Robert Klein Kromhof
Robert Klein Kromhof

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

Related Questions