Javascript 无法在主干应用程序中呈现已成功路由的视图
在我不断的自我思考过程中,通过构建,我找到了解决问题的方法,并遇到了新的问题 现在成功地从第一个视图路由到第二个视图。但是页面并没有被新的html视图填充 路由散列和路由方法来自我使用的路由器定义:fiddle line:75 onJavascript 无法在主干应用程序中呈现已成功路由的视图,javascript,backbone.js,Javascript,Backbone.js,在我不断的自我思考过程中,通过构建,我找到了解决问题的方法,并遇到了新的问题 现在成功地从第一个视图路由到第二个视图。但是页面并没有被新的html视图填充 路由散列和路由方法来自我使用的路由器定义:fiddle line:75 on routes: { '/posts/postform': 'viewPostForm', '': 'viewPosts' }, viewPostForm: function(){ console.log("r
routes: {
'/posts/postform': 'viewPostForm',
'': 'viewPosts'
},
viewPostForm: function(){
console.log("router method viewPostForm have been reached.");
this.postformview = new postFormView();
//!!the call of render and appending el of view to a the toplevel el defined at router may be neccesssary.
$(this.body).html( this.postformview.render().el );
}
postformview的定义:fiddle line:54
var postFormView = Backbone.View.extend({
template: _.template( $('#postFormTemplate').html() ),
render: function(){
this.$el.html( this.template() );//?where in dom zis the this.el
return this;
}
});
缺少的东西是什么?删除url开头的
/
,该方法将在routes哈希中创建并呈现第二个视图,这将使其正常工作
routes: {
'posts/postform': 'viewPostForm',
'': 'viewPosts'
},
您确定此方法是响应被击中的路由而触发的吗?在您的代码中,this.body是-?this.body是通过body在路由器def中设置的:“body”属性,用于使视图更独立于dom,并在路由器中具有所有这些依赖关系。您可以发布通过添加postFormView更新的
postFormView
的定义吗def。很抱歉格式化,远离我最擅长的键盘。