Accessing Ember-CLI Nested Controllers

后端 未结 2 582
半阙折子戏
半阙折子戏 2021-01-28 06:30

This is my directory structure:

controllers/
---- restaurant/
    ----items.js
---- index.js
---- restaurant.js

And my router declaration:

相关标签:
2条回答
  • 2021-01-28 06:37

    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);
        }
    }
    
    0 讨论(0)
  • 2021-01-28 06:45

    I don't think you're Items controller needs to be in the subfolder restaurant. Move it up a level and see if that fixes the issue.

    0 讨论(0)
提交回复
热议问题