2014-04-24 2 views
0

백본보기에서 변수를 사용하는 방법은 무엇입니까?백본보기에서 변수를 사용합니다. 백본보기에서 탐색합니다.

내가 아래와 같이 작동하는 경우 (아래) ... 작동하지 않습니다.

App.Views.Incentive = Backbone.View.extend({ 

     el: $('#projet-page'), 
     name: "Incentive", 
     initialize: function() { 
      "use strict"; 
      $('section[data-projet-page="' + this.name + '"] a.OpenGalerie').on('click', this.enterGalerieClick); 
     }, 
     enterProjectClick: function() { 
      Backbone.history.navigate('!/case-projet/' + this.name + '/Galerie'), 
      $('section[data-projet-page="' + this.name + '"]').css('display', 'block'), 
     }, 

    }); 

는 내가 가지고 :

도메인! 9000/#/케이스 - 인텔리 // 갤러리 대신 도메인! 9000/#/케이스 - 인텔리/인센티브/갤러리에게

+1

작동하지 않습니다. 이름 변수에 액세스하는 방식이 정확합니다. –

+0

답례로 this.name = ""(비어 있음)입니다. "인센티브"가 아닙니다 – Dossp

+0

자세한 내용 지금 ... – Dossp

답변

0

밑줄의 bind 방법 (documentation 참조)을 사용하여 클릭 핸들러의 this이 처리기를 바인딩 한 요소가 아니라 백본보기를 참조하는지 확인하여 즉각적인 문제를 해결할 수 있습니다.

App.Views.Incentive = Backbone.View.extend({ 

     el: $('#projet-page'), 
     name: "Incentive", 
     initialize: function() { 
      "use strict"; 
      $('section[data-projet-page="' + this.name + '"] a.OpenGalerie').on('click', _.bind(this.enterGalerieClick, this)); 
     }, 
     enterProjectClick: function() { 
      Backbone.history.navigate('!/case-projet/' + this.name + '/Galerie'), 
      $('section[data-projet-page="' + this.name + '"]').css('display', 'block'), 
     }, 

    }); 
관련 문제