我有一個觀點在.js文件分開「的index.html」文件看起來像這樣:多文件Backbone.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;
}
});
我分配在該視圖'index.html'使用JQuery的ready函數:
<div id="article">
</div>
<script type="text/javascript">
$(function(){
console.log($('#article'));
new window.App();
});
</script>
正如您所猜測的,「呈現」不會出現在DOM上。問題是,當我把所有東西放在一起時(視圖和標籤中的分配),它就可以工作。
任何想法?
這是什麼'的console.log(window.App)'有,如果你把它說在'$(函數(){...})'? –
'function(){a.apply(this,arguments)}' – Muenodi