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 ...
随机推荐
- 5、Cocos2dx 3.0游戏开发找小三之測试例子简单介绍及小结
重开发人员的劳动成果.转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/27186557 測试例子简单介绍 Cocos2d-x ...
- python常用内置模块,执行系统命令的模块
Subprocess模块 python3.5将使用Subprocess模块跟操作系统进行交互,比如系统命令,他将替换 os.system os.spawn* subprocess.run()方法封装的 ...
- LinkedBlockingQueue(lbq)阻塞队列
最近开发中,经常使用这个类LinkedBlockingQueue,它是BlockingQueue这个子类. 并发库中的BlockingQueue是一个比较好玩的类,顾名思义,就是阻塞队列.该类主要提供 ...
- 【PHP】使用openssl进行Rsa长数据加密(117)解密(128)
PHP使用openssl进行Rsa加密,如果要加密的明文太长则会出错,解决方法:加密的时候117个字符加密一次,然后把所有的密文拼接成一个密文:解密的时候需要128个字符解密一下,然后拼接成数据. 加 ...
- xcode 4.6 破解及真机调试
从安卓到IOS,从 eclipse 到xcode跨度还是比较大的.在研究的过程中发现,许多时候不仅仅是C,C++,JAVA和OBJECT-C的区别,相对于编程语言来说,操作习惯和开发工具带来的困惑要 ...
- JS-【同页面多次调用】tab选项卡封装
这两天遇到一个页面,同一个页面中同一个特效会用好多次,比如tab,比如轮播等.我又不想很不负责任的复制一遍代码,那样页面臃肿,自己心里也堵得慌.于是就想着把代码封装起来多次调用. 对于封装,只在公开课 ...
- 浅析HTTPS与SSL原理
版权声明:本文由盛旷 原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/134 来源:腾云阁 https://www.qclo ...
- 【Android N 7.1.1】 处于锁屏界面时可以转屏
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowManager.ja ...
- Nmap的活跃主机探测常见方法
最近由于工作需求,开始对Nmap进行一点研究,主要是Nmap对于主机活跃性的探测,也就是存活主机检测的领域. Nmap主机探测方法一:同网段优先使用arp探测: 当启动Namp主机活跃扫描时候,Nma ...
- Windows域的相关操作
一.windows域账户组操作: net group /domain #查看所有组 net group GROUP-NAME /domain #查看某一个组 net group GROUP-NAME ...