2014-10-20 5 views
0

Backbone Marionette itemview를 Foundation Reveal 모달로 이동하여 모달 팝업을 구축하고 있습니다. 모달은 나타나지만 이벤트는 발생하지 않습니다. 특히 클릭 이벤트를 잡으려고합니다.Backbone Marionette events, Zurb Foundation의 공개 모달

마리오 넷 레이아웃보기에서 Foundation을로드합니다.

'use strict'; 

    define([ 
     'jquery', 
     'underscore', 
     'backbone', 
     'region/actionbar', 
     'region/modal', 
     'text!/js/template/global.ejs', 
     'js/views/actionbar/actionbar.js', 
     'less!/style/global.less', 
     'css!/js/bower_components/foundation/css/foundation.css', 
     '/js/bower_components/foundation/js/foundation/foundation.js', 
     '/js/bower_components/foundation/js/foundation/foundation.reveal.js', 
     'marionette' 
    ], function ($, _, Backbone, ActionBar, Modal, Template, ActionBarView) { 

     var GlobalLayout = Backbone.Marionette.Layout.extend({ 
      template: _.template(Template), 

      el: 'body', 

      regions: { 
       content: "#content", 
       actionBar: ActionBar, 
       modal: '#modal' 
      }, 

      initialize: function(){ 
      }, 

      onRender: function(){ 
       // Load foundation 
       $(document).foundation(); 
      }, 

      title: function(title) { 
       // this.actionbar.title(title); 
       // document.title = "Workbench :: " + title; 
      } 
     }); 

     var layout = new GlobalLayout(); 
     layout.render(); 


     return layout; 
    }); 

팝업은 작업 표시 줄 영역의보기에서 클릭 이벤트에서로드되고 있습니다. Region :

'use strict'; 

define([ 
    'jquery', 
    'underscore', 
    'backbone', 
    'marionette' 
], function ($, _, Backbone) { 

    var ActionBar = Backbone.Marionette.Region.extend({ 
     el: "#action-bar" 

    }); 

    return ActionBar; 

}); 

... 여기에 해당 지역의보기가 있습니다. onSignUp() 내 SignUp 모달을 모달 영역으로 막습니다. 그런 다음 재단을 다시 초기화합니다.

'use strict'; 

define([ 
    'jquery', 
    'underscore', 
    'backbone', 
    'layout/global', 
    '/js/views/modals/sign-up.js', 
    '/js/views/modals/sign-in.js', 
    'model/user', 
    'text!/js/template/actionbar/actionbar.ejs', 
    'less!/style/global.less', 
    'marionette' 
], function ($, _, Backbone, layout, SignUp_Modal, SignIn_Modal, User, Template) { 

    var ActionBarView = Backbone.Marionette.ItemView.extend({ 

     initialize: function(){ 
      this.setElement('#action-bar'); 
     }, 

     template: _.template(Template), 

     events: { 
      "click .sign-in" : "onSignIn", 
      "click .sign-up" : "onSignUp" 
     }, 

     onSignUp: function(e){ 
      // e.preventDefault(); 

      layout.modal.show(new SignUp_Modal()); 
      $(document).foundation(); 

     }, 

     onSignIn: function(e){ 
      // Prevent the link from doing anything. 
      e.preventDefault(); 

      // Load modal popup that requests user to sign in  
      layout.modal.show(new SignIn_Modal()); 
      $(document).foundation(); 
     } 

    }); 

    return ActionBarView; 
}); 

마지막으로, 여기 내 SignUp_Modal보기 및 해당 템플릿이 있습니다.

'use strict';

define([ 
    'jquery', 
    'underscore', 
    'model/user', 
    'text!/js/template/modals/sign-up.ejs', 
    'marionette' 
], function ($, _, User, Template){ 
    var Modal = Backbone.Marionette.ItemView.extend({ 

     events: { 
      'click #join': 'onJoin', 
      'click .me': 'onJoin' 
     }, 

     template: _.template(Template), 

     onJoin: function(e){ 
      // Check whether the click events do anything 
      console.log('Heard it'); 
     } 

    }); 

    return Modal; 
}); 

템플릿 : 나는 이들의 도움이 될 것이라고 장담

<div id="signUp" class="reveal-modal" data-reveal> 
    <form> 
     <div class="row"> 
     <div class="small-8"> 
      <div class="row"> 
      <div class="small-3 columns"> 
       <label for="email" class="right inline">Email</label> 
      </div> 
      <div class="small-9 columns"> 
       <input type="text" id="email" placeholder="Email"> 
      </div> 
      </div> 
      <div class="row"> 
      <div class="small-3 columns"> 
       <label for="phone" class="right inline">Phone</label> 
      </div> 
      <div class="small-9 columns"> 
       <input type="text" id="phone" placeholder="Phone"> 
      </div> 
      </div> 
      <div class="row"> 
      <div class="small-3 columns"> 
       <label for="pass" class="right inline">Password</label> 
      </div> 
      <div class="small-9 columns"> 
       <input type="password" id="pass"> 
      </div> 
      </div> 
      <div class="row"> 
       <label>Username will be...</label> 
       <input type="radio" name="username" value="email" id="username_email" checked><label for="username_email">Email</label> 
       <input type="radio" name="username" value="phone" id="username_phone"><label for="username_phone">Phone</label> 
      </div> 
      <div class="row"> 
      <div class="small-3 columns"> 
       <a href="#" class="button postfix" id="join">Join</a> 
      </div> 
      </div> 
     </div> 
     </div> 
    </form> 
      <div class="me">blaaaa</div> 
    <a class="close-reveal-modal">&#215;</a> 
</div> 

:

  • 상용구 예는 백본 프로젝트 Zurb 재단을 구현하는 방법을 보여주는 구체적으로 어디에 ' 기본 모달로 백본보기 재밍?
  • 조회수가 클릭 이벤트를 듣지 않는 일반적인 이유는 무엇입니까?
  • 뷰를 영역에 부적절하게로드 했습니까?

오류는 특히 class = "me"또는 id = "join"인 요소를 클릭 할 때 발생합니다. 이 두 가지 모두 onJoin()을 호출해야하지만 둘 다 호출하면 안됩니다.

답변

2

파운데이션이 모달을 보유 할 새 DOM 요소를 생성하기 때문에 이벤트가 트리거되지 않습니다.이 요소는 ItemView의 인스턴스 el 외부에 있으며 뷰와 연관된 요소에만 이벤트를 위임합니다.

+0

어떻게 해결할 수 있습니까? – user1801879

관련 문제