首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Ember.Container的用途是什么

Ember.Container的用途是什么
EN

Stack Overflow用户
提问于 2012-12-30 04:42:51
回答 2查看 7.8K关注 0票数 18

谁能解释一下最新的Ember中Container模块的用途是什么?

在设置和本测试开始时,它的用法示例如下:

module("Ember.View - handlebars integration", {
  setup: function() {
    Ember.lookup = lookup = { Ember: Ember };
    lookup.TemplateTests = TemplateTests = Ember.Namespace.create();

    container = new Ember.Container();
    container.optionsForType('template', { instantiate: false });
  }

test("template view should call the function of the associated template", function() {
  container.register('template', 'testTemplate', Ember.Handlebars.compile("<h1 id='twas-called'>template was called</h1>"));
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-12-30 15:35:49

容器的目标是提供一种比我们一直使用的ad-hoc方法更通用的机制来描述模块依赖关系。

例如,假设您想要查找post路由的控制器。默认的Ember规则是我们将其查找为App.PostController。在容器之前,我们只需在需要查找的地方硬编码这些规则(使用classify和朋友)。

容器为我们提供了一种在单一位置定义这些规则的方法。额外的好处是,对于需要不同约定的应用程序,可以覆盖这些规则。

因此,我们现在使用container.lookup('controller:' + name),而不是内部的Ember.get(namespace, Ember.String.classify(name) + 'Controller')

票数 34
EN

Stack Overflow用户

发布于 2013-01-07 18:12:45

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14085749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档