0
A
답변
1
요약하면 :parent
선택기 해킹을 기꺼이하지 않는 한 선언적 events
해시를 사용할 수 없습니다. 그렇다고해도 가능한지 확실하지 않습니다.
문제는 jQuery를 선택하면 (클래스 선택 .booked
예를 들어) view's el
내 을 적용되는 요소를 정의하는 데 사용하는, 그래서 요소의 자신의 클래스는 선택에서 고려되지 않습니다.
대신 동적으로 처리기 메서드를 설정합니다. 다음과 같이 입력하십시오 :
events: {
'click': 'onClick'
},
render: function(){
if(this.model.get('id_bookings')){
this.clase = 'booked';
this.onClick = this.showReservation;
}
if(this.model.get('id_guests')){
this.clase = 'occupied';
this.onClick = this.showGuest;
}else{
this.clase = 'free';
this.onClick = this.checkIn;
}
_.bindAll(this, 'onClick');
this.$el.addClass(this.clase).html(this.template(this.model.toJSON()));
return this;
},
1
간단하게 유지하십시오. 단추에 대한 하나의 클릭 처리기를 설정하고 올바른 방법으로 프록시 처리해야합니다.
App.Views.Bed = Backbone.View.extend({
tagName: 'li',
template: _.template(App.Templates.Bed),
events: {
'click': 'click_handler'
},
render: function(){
if(this.model.get('id_bookings')){
this.clase = 'booked';
}
if(this.model.get('id_guests')){
this.clase = 'occupied';
}else{
this.clase = 'free';
}
this.$el.addClass(this.clase).html(this.template(this.model.toJSON()));
return this;
},
click_handler: function() {
if (this.$el.hasClass('booked')) {
this.showReservation();
} else if (this.$el.hasClass('occupied')) {
this.showGuest();
} else if (this.$el.hasClass('free')) {
this.checkIn();
} else {
// oops!?
}
},
checkIn: function(){
console.log('Check-in form load');
},
showReservation: function(){
},
showGuest: function(){
}
});
관련 문제
- 1. jQuery를 - 클래스 명
- 2. 후속 : 클래스 명
- 3. 프로토 타입 : 클래스 명
- 4. 백본보기
- 5. 백본보기
- 6. 내 페이지의 중간에 클래스 명
- 7. 백본보기 이벤트
- 8. 백본보기 출력
- 9. 백본보기 상속
- 10. 백본보기 문제
- 11. 백본보기 상속
- 12. 백본보기 저장 (모범 사례)
- 13. jQuery의 $의 ExtJS에 해당하는 (". 클래스 명"부모)
- 14. 보기를 만드는 백본보기
- 15. 백본보기 DOM 요소가 제거되었습니다.
- 16. 자체 백본보기 초기화
- 17. 백본보기 collection.each() bug?
- 18. 백본보기 이벤트가 모든보기에 도달했습니다.
- 19. 백본보기 끝에서 무엇을 반환해야합니까?
- 20. 백본보기 - 정의되지 않았습니다.
- 21. 백본보기, 초기화 및 렌더링
- 22. 사용자 지정 메서드가있는 백본보기
- 23. 백본보기 및 window.getSelection
- 24. 내가 상속 백본보기가 백본보기
- 25. 백본보기 초기화시 필터링되지 않음
- 26. 백본보기 템플릿에 추가 사용
- 27. 라우터에서 백본보기 제거
- 28. 아이 백본보기 '이'부모
- 29. 백본보기 액세스 방법 변수
- 30. 백본보기 - jquery 이벤트 바인딩