BackboneJS를 사용하여 하위 뷰에서 뷰 기능을 호출 할 수 있는지 알고 싶습니다. 예인 경우 어떻게 작동합니까?BackboneJS를 사용하여 하위 뷰에서 뷰 기능 호출
하위 뷰에서 mainView에 속한 "hello"함수를 호출하려고합니다. 이벤트가 트리거 어쩌면 경우
...
예 :
var MainView = Backbone.View.extend({
initialize: function() {
this.$template = $(template);
this.subview = new SubView();
this.render();
},
render: function() {
this.$el.html(this.$template);
var element = this.$template.attr('id');
this.subview.setElement('#'+element).render();
},
hello: function() {
alert('Hello');
}
});
var SubView = Backbone.View.extend({
initialize: function() {
this.$template = $(template);
this.render();
},
render: function() {
this.$el.html(this.$template);
//Call view function ' hello '
//parentView.hello();
}
});
감사합니다!
당신은 당신의 서브 뷰에 부모 뷰에서 참조를 전달할 수 있습니다
'var SubView = Backbone.MainView.extend'를 사용하여'MainView'를 확장 해 보았습니까? 그러면'SubView '에서'hello' 함수를 호출 할 수 있습니다. –