0
这是我的支柱代码骨干查看:可以不是视图追加到先前渲染视图
app.js
window.App = {
Models: {},
Views: {}
};
window.Template = {};
应用程序/ 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);
}
});
应用程序/模板.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");
app/views/l ayout.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的问题,但我无法弄清楚如何以及为什么...