Mates,我试图从子视图访问骨干视图的属性(不知道是否是正确的面额)。 无论如何,这里有一些代码:
App.Views.ViewEditGuest = Backbone.View.extend({
el: '#main-content .container_12',
totalPayments: 0,
totalBought: 0,
template: _.template( App.Templates.ViewEditGuest ),
events: {
'click #sell' : 'sell'
},
sell: Backbone.View.extend({
el: '#consumos',
template: _.template( App.Templates.VEGConsumos ),
render: function(){
// I need to acces ViewEditGuest's totalPayments and
// totalBought
this.$el.html( this.template() );
return this;
}
}),
render: function(){
this.$el.html( this.template( ) );
return this;
}
});
因此,我需要从sell的render方法访问ViewEditGuest的totalPayments和totalBought。 我一直在寻找周围,但找不到任何解决方案。
有什么想法吗?
谢谢!
答案 0 :(得分:2)
但要尽可能少地修改代码来回答问题,
sell: Backbone.View.extend({
parentView: this,
el: '#consumos',
template: _.template( App.Templates.VEGConsumos ),
render: function(){
console.log( options.parentView.totalBought );
this.$el.html( this.template() );
return this;
}