業餘這個問題可能是,但沒有人可以用一隻手。剛剛從包裝中脫穎而出,開始了Hello World的示例,但似乎無法啓動並運行。有人可能會告訴我爲什麼我沒有看到這個結果?骨幹入門
(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>
您應該可以通過使用'el:'body','將'el'設置爲'body'。你不需要把它包裝在一個jQuery對象中。 – Jack