我对以下代码有疑问:reward_view
没有填充 div。渲染函数正在运行,但this.el
似乎未定义,为什么?
var ListView = Backbone.View.extend({
el: '#reward_view',
initialize: function(){
_.bindAll(this, 'render'); // every function that uses 'this' as the current object should be in here
},
render: function(){
console.log(this)
console.log(this.el)
$(this.el).html('<h1>Hello' + '</h1>');
return this; // for chainable calls, like .render().el
}
});
var myItem = new Item();
myItem.fetch();
var reward_view = new ListView({model:myItem});
reward_view.render();
HTML:
<div id="reward_view" class="bs-callout bs-callout-info">
</div>