我想知道是否可以使用 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();
}
});
谢谢!