我正在为一个项目评估 Backbone,并且在让它输出基于绑定到 id 的最简单视图时遇到问题。这是代码,我确定我犯了一个完全的菜鸟错误:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src='underscore.js'></script>
<script src='backbone.js'></script>
<script>
var BandView=Backbone.View.extend({
el:$('#bands-wrapper'),
initialize: function(){
_.bindAll(this,'render');
console.log('you initialized');
this.render();
},
render:function(){
console.log('you are about to render');
this.$el.text('here i am');
return this;
}
});
var myView=new BandView();
</script>
<body>
before
<div id='bands-wrapper'>
after
我没有收到错误消息,并且两条错误消息都写入控制台。知道我做错了什么吗?
谢谢