问题描述
这是我的目录结构:
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"
});
});
我的商品控制器(位于restaurants / 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错误说餐厅需要添加到需求:
However, I keep getting hte error saying "restaurant" needs to be added to "needs":
这是我的设置(Ember-CLI 0.1.2 with 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?
推荐答案
自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嵌套控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!