Javascript 当遵循指向路由的超链接时,主干';s View.render方法执行,但不执行';不要应用这些更改
我在主干应用程序中定义了一些简单的静态视图,我正在尝试向等式中添加一些子视图 直接导航到管线时,子视图会正确渲染,但如果通过超链接导航到管线,则布局会正确渲染,但子视图不会 似乎有些东西超出了范围或尚未初始化,但需要一些帮助来确定是什么 路由器Javascript 当遵循指向路由的超链接时,主干';s View.render方法执行,但不执行';不要应用这些更改,javascript,backbone.js,Javascript,Backbone.js,我在主干应用程序中定义了一些简单的静态视图,我正在尝试向等式中添加一些子视图 直接导航到管线时,子视图会正确渲染,但如果通过超链接导航到管线,则布局会正确渲染,但子视图不会 似乎有些东西超出了范围或尚未初始化,但需要一些帮助来确定是什么 路由器 App.Router = Backbone.Router.extend({ routes: { "": "home", "tmp": "tmp", }, home: function() {
App.Router = Backbone.Router.extend({
routes: {
"": "home",
"tmp": "tmp",
},
home: function() {
var home = new App.Views.HomeLayout();
},
tmp: function() {
var tmp = new App.Views.TmpLayout();
}
});
视图
App.Views.HomeLayout = Backbone.View.extend({
el: $('body'),
template: _.template($('#tmplLayout').html()),
initialize: function() {
this.render();
},
render: function() {
$(this.el).append(this.template());
var menu = new App.Views.HomeMenuView({el: this.$('#menu')});
menu.render();
var page = new App.Views.HomeView({el: this.$('#content')});
page.render();
return this;
}
});
App.Views.HomeMenuView = Backbone.View.extend({
template: _.template($('#tmplHomeMenu').html()),
render: function() {
$(this.el).html(this.template());
return this;
}
});
App.Views.HomeView = Backbone.View.extend({
template: _.template($('#tmplHome').html()),
render: function() {
$(this.el).html(this.template());
return this;
}
});
应用程序在my index.html(也是所有“我的视图”模板的位置)中使用以下内容初始化:
<script>
new App.Router();
Backbone.history.start();
</script>
新的App.Router();
Backbone.history.start();
tmp视图基本上是上述内容的复写本,但具有不同的模板
我尝试过的事情:
- 我把子视图移动到路由器上,没有变化李>
- 在每个子视图中调用render初始化方法(类似于布局视图的定义方式),不做任何更改
extend
调用中提供el:$('body')
是不正确的。你应该通过el:$('body'))
初始化视图时:var home=new App.Views.homeloayout({el:$('body')})代码>