バックボーンを使用してユーザー認証用のビューをレンダリングする小さなアプリを作成しようとしています。ここにフィドルのデモがありますhttp://jsfiddle.net/mjmitche/RRXnK/182/
初期化時に、AuthView によって配置された div "span6 authentication" に 3 つのリンクが表示されます。
<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>
AuthView には 3 つのクリック イベントが設定されています。
events: {
'click .row.authentication a#login': 'login',
'click .row.authentication a#signup': 'signup',
'click .row.authentication a#retrievePassword': 'retrieve'
},
たとえば、サインアップをクリックすると(フィドルのように)、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);
},
しかし、それは機能していません。フィドルでわかるように、2 番目のアラートはトリガーされません。これが登録ビューです。
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 はコードが有効であると言っています。