これが私のバックボーンコードです
app.js
window.App = {
Models: {},
Views: {}
};
window.Template = {};
app/router.js
App.Router = Backbone.Router.extend({
initialize: function () {
Backbone.history.start({pushState: true});
App.layout = new App.Views.Layout();
App.layout.render();
$('#app').append(App.layout.el);
},
routes: {
'': 'index'
},
index: function () {
console.log('index routed.');
App.home = new App.Views.Home();
App.home.render();
$('#content').html(App.home.el);
}
});
app/templates.js
Template.layout = _.template(
"<header id=top-bar>"+
"<nav id=user-panel>"+
"<ul>"+
"<li><a class=login href=#>Login</a></li>"+
"<li><a class=register href=#>Registrati gratis</a></li>"+
"</ul>"+
"</nav>"+
"</header>"+
"<div id=wrapper>"+
"<section id=mid-bar>"+
"<a id=logo href=#><img src=public/img/logo.png></a>"+
"</section>"+
"<section id=content>"+
"</section>"+
"</div>"
);
Template.home = _.template("Benvenuto in Virtualmix");
アプリ/ビュー/layout.js
App.Views.Layout = Backbone.View.extend({
id: 'container',
template: Template.layout,
render: function () {
this.$el.html(this.template);
}
});
アプリ/ビュー/home.js
App.Views.Home = Backbone.View.extend({
tagName: 'p',
template: Template.home,
render: function () {
this.$el.html(this.template);
}
});
そして最後に私のmain.js
$(document).ready(function () {
App.router = new App.Router;
});
まあ、レイアウトビュー(ルーター初期化関数から初期化された...)は正しくレンダリングされますが、インデックス関数から初期化およびレンダリングされたホームビューは、以前に生成されたレイアウトに何も出力しないようです(私は#レイアウトによって生成された content 要素...)。
JQueryの問題だと思いますが、その方法と理由がわかりません...