不要使用它。其中一位核心开发人员表示,每当有人试图使用App.__container__
时,他会添加另一个下划线。
如果您确实想访问Ember.View intance,请使用Ember.View.views['foo']
。其中foo
是视图实例的elementId
。
所以,如果,例如,你想要的App.ApplicationView
实例:
App.ApplicationView = Ember.View.extend({
elementId: 'application'
});
// somewhere else in your code
var applicationViewInstance = Ember.View.views['application'];
话虽如此,我从未遇到过,我需要访问这样的视图实例的情况来了。如果您可以发布您的用例,我可能会提出其他方法。
UPDATE:您想要访问的图实例的一些性质,从一些其它视图的实例(图的高度和宽度)。你可以通过这些属性来控制,并让其他控制器访问它们在其他视图中使用它们(源视图 - >源控制器 - >一些其他的控制器 - >其他一些视图):
App.ApplicationView = Ember.View.extend({
didInsertElement: function() {
var controller = this.get('controller'),
height = this.$().height(),
width = this.$().width();
controller.setProperties({
height: height,
width: width
});
}
});
App.SomeotherController = Ember.Controller.extend({
needs: ['application'],
applicationViewWidthBinding: 'controllers.application.width',
applicationViewHeightBinding: 'controllers.application.height'
});
App.SomeOtherView = Ember.View.extend({
// assuming its controller is an instance of App.SomeotherController
applicationViewWidthBinding: 'controller.applicationViewWidth',
applicationViewHeightBinding: 'controller.applicationViewHeight'
});
谢谢你的答案,我用用例更新了我的描述 –
您的更新似乎是正确的Ember解决方案,但您是否觉得让控制器参与管理演示会很奇怪? –