1. 有时候,特别是当嵌套资源的时候,我们需要两个controllers之间的某种连接。让我们拿这个router当做例子:

app/router.js

var Router = Ember.Router.extend({});

Router.map(function() {
this.route("post", { path: "/posts/:post_id" }, function() {
this.route("comments", { path: "/comments" });
});
}); export default Router;
  • 如果我们访问/posts/1/comments URL,我们的post model将会被加载进一个PostController的model,意思就是它不能直接的在CommentsController中被访问。我们也许想在comments模板中展示一些关于它的信息。
  • 我们可以这样做,我们把PostController注入CommentsController

app/controllers/comments.js

export default Ember.Controller.extend({
postController: Ember.inject.controller('post')
});

一旦comments访问PostController,一个只读别名可以被用来从哪个controller中读取model。为了获取Post model,我们参考postController.model:

app/controllers/comments.js

export default Ember.Controller.extend({
postController: Ember.inject.controller('post'),
post: Ember.computed.reads('postController.model')
}); 

app/templates/comments.hbs

<h1>Comments for {{post.title}}</h1>

<ul>
{{#each model as |comment|}}
<li>{{comment.text}}</li>
{{/each}}
</ul>

2. 在Ember.js中想要获取更多的关于依赖注入的信息,请看dependency injection guide

3. 想要获得更多关于别名的信息,请看的aliased properties.API。

6.3 Controllers -- Managing Dependencies Between Controllers的更多相关文章

  1. Presenting view controllers on detached view controllers is discouraged <CallViewController: 0x14676e240>.

    今天在优化app时,发现程序出现这种警告:“ Presenting view controllers on detached view controllers is discouraged <C ...

  2. iOS Programming Autorotation, Popover Controllers, and Modal View Controllers

    iOS Programming Autorotation, Popover Controllers, and Modal View Controllers  自动旋转,Popover 控制器,Moda ...

  3. Presenting view controllers on detached view controllers is discouraged

    本文转载至 http://www.xuebuyuan.com/2117943.html Presenting view controllers on detached view controllers ...

  4. iOS错误之-Presenting view controllers on detached view controllers is discouraged

    遇到这个警告后找了一下网络资源,基本上只说通过 [self.view.window.rootViewController presentViewController:controller animat ...

  5. 3: 组件间的依赖管理 Managing Dependencies Between Components Using the Prism Library 5.0 for WPF(英汉对照版)

    Applications based on the Prism Library are composite applications that potentially consist of many ...

  6. xocde8打印出:Presenting view controllers on detached view controllers is discouraged

    原因: 是某个viewController的生命周期控制出现了错误,所以尽量避免一个controller的view去addsubview另一个controller的view,这样会破坏层级关系,导致第 ...

  7. Ember.js学习教程 -- 目录

    写在前面的话: 公司的新项目需要用到Ember.js,版本为v1.13.0.由于网上关于Ember的资料非常少,所以只有硬着头皮看官网的Guides,为了加深印象和方便以后查阅就用自己拙劣的英语水平把 ...

  8. 【IOS笔记】Creating Custom Content View Controllers

    Creating Custom Content View Controllers 自定义内容视图控制器 Custom content view controllers are the heart of ...

  9. View Controller Programming Guide for iOS---(四)---Creating Custom Content View Controllers

    Creating Custom Content View Controllers 创建自定义内容视图控制器 Custom content view controllers are the heart ...

随机推荐

  1. Tomcat 8(九)解读Tomcat组件的生命周期(Lifecycle)

    Tomcat 8(七)解读Bootstrap介绍过.运行startup.bat.将引发Tomcat一连串组件的启动.事实上这一连串启动是通过组件的生命周期(Lifecycle)实现的 今天来看看Lif ...

  2. opencascade读取iges并用vtk离散的一些问题

    近期抽时间在弄iges文件内容读取的工作.然后将其离散化在vtk中能够显示处理以及兴许的一些工作.主要目的是识别CAD文件导出的模型,然后进行离散处理.方便兴许的处理.离散工作比較简单.opencas ...

  3. JAVA语言基础内部测试题(50道选择题)

    JAVA语言基础内部测试题 选择题(针对以下题目,请选择最符合题目要求的答案,针对每一道题目,所有答案都选对,则该题得分,所选答案错误或不能选出所有答案,则该题不得分.)(每题2分) 没有注明选择几项 ...

  4. 九度 1500:出操队形(LIS变形)

    题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往楼下跑了,然后身高矮的排在队伍的前面,身高较高的就要排在队尾.突然,有一天出操负责人想了一个 ...

  5. MySQL技术内幕:SQL编程 第2章 数据类型 读书笔记

    2.1 类型属性 2.1.1 UNSIGNED 数字无符号化, INT的值 -2147483648 ~ 2147483647  INT UNSIGNED的值 0 ~ 4294967295 int a ...

  6. django 错误分类及解决办法汇总

    问题1:启动服务器后浏览器无法访问http://localhost:8000,访问被拒绝

  7. 关于.NET玩爬虫这些事

    这几天在微信群里又聊到.NET可以救中国但是案例太少不深的问题,我说.NET玩爬虫简直就是宇宙第一,于是大神朱永光说,你为何不来写一篇总结一下? 那么今天就全面的来总结一下,在.NET生态下,如何玩爬 ...

  8. 测试sql语句性能,提高执行效率

    为了让您的程序执行的效率更高,SQL的效率一定不可忽视. 现有以下方法去检测SQL的执行效率. 对于多表查询的效率测试: )直接from ,where方式. SET STATISTICS io ON ...

  9. poj_2709 贪心算法

    poj 2709 painter 题目要求 给定涂料,每套涂料含有3-12种不同的颜色(开始时候给定选用的颜料套的颜色数目),且一套涂料中每种颜色均有50ml.且一套涂料中的任意三种不同的颜色各X m ...

  10. 设计模式-UML类图基础

    设计模式之序-UML类图那点事儿 打14年年底就像写那么一个系列,用于讲设计模式的,代码基于JAVA语言,最早接触设计模式是大一还是大二来着,那时候网上有人给推荐书,其中就有设计模式,当时给我推荐的书 ...