Tôi muốn biết liệu có thể gọi chức năng xem từ một chế độ xem con với BackboneJS hay không. Nếu có, nó hoạt động như thế nào?Chức năng xem cuộc gọi từ subview với BackboneJS
Tôi muốn gọi hàm "hello" thuộc về chế độ xem chính từ chế độ xem phụ.
Có lẽ nếu sự kiện kích hoạt ...
Ví dụ:
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();
}
});
Cảm ơn!
bạn đã thử mở rộng 'MainView' bằng' var SubView = Backbone.MainView.extend' chưa? Điều đó sẽ cho phép bạn gọi hàm 'hello' từ bên trong' SubView'. –