问题描述
这是我的目录结构:
controllers/
---- restaurant/
----items.js
---- index.js
---- restaurant.js
还有我的路由器声明:
this.route("restaurants",{
path: "/restaurants"
});
this.resource("restaurant", {
path: "/restaurants/:restaurant_id"
}, function() {
this.resource("items", {
path: "/items"
});
});
My Items 控制器(位于 restaurant/items.js)以以下内容开头:
My Items controller (located in restaurants/items.js) begins with the following:
export default Ember.ObjectController.extend({
needs: ["restaurant"],
restaurant: Ember.computed.alias('controllers.restaurant.model')
然后是将项目添加到 hte restaurant 下的操作.
and is then followed by an action to add the item under hte restaurant.
但是,我不断收到错误消息,提示需要将餐厅"添加到需求"中:
However, I keep getting hte error saying "restaurant" needs to be added to "needs":
ReferenceError: (generated items controller)#needs 不包括 restaurant
.要从(生成的项目控制器)访问餐厅控制器,(生成的项目控制器)应该有一个 needs
属性,该属性是它可以访问的控制器数组
这是我的设置(Ember-CLI 0.1.2 和 Ember 1.7) - 因为我使用壁炉适配器来处理 firebase,我认为它不支持升级 Ember(根据我的尝试).
This is my setup (Ember-CLI 0.1.2 with Ember 1.7) - As i'm using the fireplace adapter to work with firebase, I don't think it supports upgrading Ember (from what I've tried).
DEBUG: -------------------------------
DEBUG: Ember : 1.7.0"
DEBUG: Ember Data : 1.0.0-beta.10"
DEBUG: Handlebars : 1.3.0"
DEBUG: jQuery : 1.11.2"
DEBUG: Fireplace : 0.2.9"
DEBUG: -------------------------------
我尝试过其他 Stackoverflow 答案(例如 如何在 Ember.js 中的控制器之间进行通信)但它们似乎没有帮助.
I've tried the other Stackoverflow answers (e.g. How to communicate between controllers in Ember.js) but they don't seem to help.
有人知道这里发生了什么吗?
Does anyone know what's going on here?
推荐答案
As of Ember-CLI v0.2.1 + Ember v1.10.0(适用于早期版本;但我还没有尝试过),这就是你的做法它:
As of Ember-CLI v0.2.1 + Ember v1.10.0 (could work for earlier versions; but I haven't tried), this is how you do it:
export default Ember.ObjectController.extend({
needs: ["restaurant/items"],
...
要访问操作,您可以这样做:
To access actions, you'd do this:
actions: {
myAction: function(arg1, arg2) {
this.get('controllers.restaurant/item').send('someItemActionYouDefine', arg1, arg2);
}
}
这篇关于访问 Ember-CLI 嵌套控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!