Backbone.js 查看isn';从其他视图中创建时不进行渲染
我正在尝试制作一个小应用程序,它使用主干来呈现用户身份验证的视图。这里有一个小提琴演示 初始化时,AuthView放置的div“span6 authentication”中会出现三个链接Backbone.js 查看isn';从其他视图中创建时不进行渲染,backbone.js,Backbone.js,我正在尝试制作一个小应用程序,它使用主干来呈现用户身份验证的视图。这里有一个小提琴演示 初始化时,AuthView放置的div“span6 authentication”中会出现三个链接 <div class="span6 authentication"> <div class="row authentication"> <a href="#login" id="login" data-toggle="tab" data-content="login
<div class="span6 authentication">
<div class="row authentication">
<a href="#login" id="login" data-toggle="tab" data-content="login">Login</a>
<a href="#signup" id="signup" data-toggle="tab" data-content="signup">Sign up</a>
<a href="#retrieve-password" id="retrievePassword" data-toggle="tab" data-content="retrievePassword">Retrieve password</a>
</div>
<div class="content" id="auth-content">I want the sign up view to appear in this div if I click on the Sign Up link</div>
</div>
例如,如果我单击signup(如在小提琴中),它将创建RegistrationView并尝试放入#auth content div
signup: function(){
alert("from signup method of auth view");
var signUpView = new UserRegistrationView({model : this.model}).render().el;
alert(signUpView);
$('#auth-content').html(signUpView);
},
但是,它不起作用。第二个警报,正如你在小提琴上看到的,没有被触发。这是注册视图
var UserRegistrationView = Backbone.View.extend({
initialize:function () {
_.templateSettings = {
interpolate : /\{\{=(.+?)\}\}/g,
escape : /\{\{-(.+?)\}\}/g,
evaluate: /\{\{(.+?)\}\}/g
};
var template = $('#signup_template').html();
this.template = _.template(template);
},
render: function(){
alert("render of Registration View");
$(this.el).html(this.template());
}
})
有人能指出这种设置可能有什么问题吗。值得一提的是,JSHint说代码是有效的 添加一个
返回这个在UserRegistrationView
看这里
这是因为您正在链接render
并访问el
属性
var UserRegistrationView = Backbone.View.extend({
initialize:function () {
_.templateSettings = {
interpolate : /\{\{=(.+?)\}\}/g,
escape : /\{\{-(.+?)\}\}/g,
evaluate: /\{\{(.+?)\}\}/g
};
var template = $('#signup_template').html();
this.template = _.template(template);
},
render: function(){
alert("render of Registration View");
$(this.el).html(this.template());
}
})