次のような「index.html」ファイルとは別に、.jsファイルにビューがあります。
window.App = Backbone.View.extend({
el: $('#article'),
initialize: function() {
_.bindAll(this, 'render');
console.log('binding');
console.log($('#article'));
this.render();
},
render: function() {
console.log('rendering');
this.$el.html("rendered");
return this;
}
});
JQuery の ready 関数を使用して、このビューを「index.html」に割り当てています。
<div id="article">
</div>
<script type="text/javascript">
$(function(){
console.log($('#article'));
new window.App();
});
</script>
ご想像のとおり、"rendered" は DOM には表示されません。問題は、すべて (ビューとタグの割り当て) をまとめてパックすると、機能することです。
何か案は ?