2013-02-10 49 views
0

我正在嘗試製作一個使用Backbone呈現用戶身份驗證視圖的小應用程序。這裏是一個小提琴演示http://jsfiddle.net/mjmitche/RRXnK/182/從其他視圖中創建視圖時不會呈現

初始化時,三個鏈接出現在div「span6認證」中,由AuthView放在那裏。

<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

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); 
    }, 

但是,它不起作用。正如你可以在小提琴中看到的那樣,第二個提示沒有被觸發。這是註冊視圖。

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說代碼是有效的。

回答