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 ...
随机推荐
- easyui------修改validatebox过滤规则
转载: http://www.cnblogs.com/zhxhdean/archive/2011/09/21/2184153.html 代码: //扩展easyui表单的验证 $.extend($.f ...
- Python cookielib 模块
什么是 cookie : 指某些网站为了辨别用户身份,进行 session 跟踪而储存在用户本地终端上的数据,通常以 txt 文件形式存储.比如你登录了淘宝,浏览器就会保存 cookie 信息,这样我 ...
- Win8/8.1下驱动安装“数据无效”错误的有效解决方法
Windows8.1 安装完vmware 后并没有安装 vmnet1,vmnet8 这两个虚拟网卡,纠结了半天,原来是两个服务没打开. 如果你使用的是Windows8或者8.1,并且精简过系统,那么在 ...
- c++ 利用new动态的定义二维数组
#include <iostream> using namespace std; int main() { , col = ; // key code: 申请空间 int **edge = ...
- setTimeout原来有这种用途
setTimeout有两个参数,第一个是需要执行的函数,第二个是将该函数推入UI队列的时间. 需要注意的两点: 1.第二个参数中设置的时间,是从执行setTimeout开始计算,而不是从整个函数执行完 ...
- jquery背景backgroundPosition插件
在jquery官网里找到(http://plugins.jquery.com/kbw.backgroundpos/) 语法: obj.animate({'background-position': ' ...
- 代码片段,Lucene的高亮显示
代码高亮显示是通过在搜索到的Term中把匹配了用户输入的关键字的周围加上一些标记来实现(比如,关键字是 "中华" 查到的一个Term是 "中华人民共和国",则把 ...
- nutch 1.7导入Eclipse
1.下载Nutch1.7的包 apache-nutch-1.7-src.zip,解压之后应该包括 bin,conf,src等目录 2.将解压之后的 apache-nutch-1.7 文件夹放到ecli ...
- DGbroker故障切换示例
1.主库故障 SQL> startup ORACLE instance started. Total System Global Area bytes Fixed Size bytes Vari ...
- Mahout实现的算法
在Mahout实现的机器学习算法见下表 算法类 算法名 中文名 分类算法 Logistic Regression 逻辑回归 Bayesian 贝叶斯 SVM 支持向量机 Perceptron 感知器算 ...