6.3 Controllers -- Managing Dependencies Between Controllers
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的更多相关文章
- Presenting view controllers on detached view controllers is discouraged <CallViewController: 0x14676e240>.
今天在优化app时,发现程序出现这种警告:“ Presenting view controllers on detached view controllers is discouraged <C ...
- iOS Programming Autorotation, Popover Controllers, and Modal View Controllers
iOS Programming Autorotation, Popover Controllers, and Modal View Controllers 自动旋转,Popover 控制器,Moda ...
- Presenting view controllers on detached view controllers is discouraged
本文转载至 http://www.xuebuyuan.com/2117943.html Presenting view controllers on detached view controllers ...
- iOS错误之-Presenting view controllers on detached view controllers is discouraged
遇到这个警告后找了一下网络资源,基本上只说通过 [self.view.window.rootViewController presentViewController:controller animat ...
- 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 ...
- xocde8打印出:Presenting view controllers on detached view controllers is discouraged
原因: 是某个viewController的生命周期控制出现了错误,所以尽量避免一个controller的view去addsubview另一个controller的view,这样会破坏层级关系,导致第 ...
- Ember.js学习教程 -- 目录
写在前面的话: 公司的新项目需要用到Ember.js,版本为v1.13.0.由于网上关于Ember的资料非常少,所以只有硬着头皮看官网的Guides,为了加深印象和方便以后查阅就用自己拙劣的英语水平把 ...
- 【IOS笔记】Creating Custom Content View Controllers
Creating Custom Content View Controllers 自定义内容视图控制器 Custom content view controllers are the heart of ...
- View Controller Programming Guide for iOS---(四)---Creating Custom Content View Controllers
Creating Custom Content View Controllers 创建自定义内容视图控制器 Custom content view controllers are the heart ...
随机推荐
- 南京IT企业环境之最深心得体会
我是南京做嵌入式的. 之前搞过一年的PC平台Linux内核开发,Linux内核态的仅仅要不是非常复杂的BUG还是能修复的.一年的Linux用户态软件开发. 然后近期搞了两年ARM嵌入式开发. 做的CM ...
- 高级类特性----static关键字
static 关键字 当我们编写一个类时,其实就是在描述其对象的属性和行为,而并没有产生实质上的对象,只有通过new关键字才会产生出对象,这时系统才会分配内存空间给对象,其方法才可以供外部调用. 我们 ...
- Access数据操作-02
数据库连接 MDB文件 :Provider=Microsoft.Jet.OLEDB.4.0;Data Source=*.mdb ;Persist Security Info=False; AccDB文 ...
- Python3 requests 库
requests 安装 使用 requests 发送 GET 请求 使用 requests 发送 POST 请求 使用 requests 维持会话 使用 requests 访问 HTTPS 使用 re ...
- ScrollView拉到尽头时出现阴影的解决方法
<code class="hljs markdown has-numbering" style="display: block; padding: 0px; col ...
- EL表达式各种函数使用大全
引入<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> ...
- SEH分析笔记(X64篇)
SEH分析笔记(X64篇) v1.0.0 boxcounter 历史: v1.0.0, 2011-11-4:最初版本. [不介意转载,但请注明出处 www.boxcounter.com 附件里有本文 ...
- php数据访问之查询关键字
本文根据数据库中的car表做一个汽车查询页面,巩固php查询关键字操作,感兴趣的小伙伴们可以参考一下 本文实例为大家分享了php查询操作的实现代码,供大家参考,具体内容如下 一.一个关键字查询 主 ...
- 【golang】 go语言之环境搭建+ 第一个go语言程序
1 下载:http://www.golangtc.com/download (以win为例) 2 安装步骤: 安装包: go1.8.windows-amd64.msi 双击进行安装 创建工作目录 :D ...
- 通过身份证分析出生年月日、性别、年龄的SQL语句
),) ) ),)<>'X' ) ) )<>'X' ),)),)),)) ),)),)),)) ) as int)) where [出生日期]<>'' #字符串格式 ...