sonobenissimo
sonobenissimo

Reputation: 301

Getting started with backbone

Amateurish this question might be but none the less could use a hand. Just got backbone out of the packaging and started the hello world example but cant seem to get it up and running. Any chance someone could tell me why Im not seeing the results of this?

(function($){

var ListView = Backbone.View.extend({
    el: $(body), //attaches this.el to an existing element

    initialize: function(){
        _.bindAll(this, 'render'); //fixes loss of context for this within elements
        this.render(); //not all views are self-rendering. This is one.
    },

    render: function(){
        $(this.el).html("<ul><li>Hello World!</li></ul>");
    }
});
var listVew = new ListView();


})(jQuery);

html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Hello Backbone </title>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script>
<script src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>

<script src="backbone.js" type="text/javascript"></script>

</body>
</html>

Upvotes: 0

Views: 229

Answers (1)

Peter Lyons
Peter Lyons

Reputation: 146154

  • I tried your code in a jsfiddle and got this error: Uncaught ReferenceError: body is not defined
    • use the string 'body' as your view's el selector

This works: http://jsfiddle.net/PeGW6/

Also note you are using a very very old version of backbone. Upgrade to the most recent build.

Upvotes: 2

Related Questions