Ember - accessing parent route's model from co

2019-08-07 09:14发布

I have two routes, let's call them /user and /user/actions. How do I access the user model from a UserActionsController method?

I've tried something like:

this.modelFor('user').get('id')

and

this.get('target').modelFor('user').get('id)

but in both cases it sais that 'modelFor' is undefined and not a function.

2条回答
欢心
2楼-- · 2019-08-07 09:38

Maybe I have not given this enough thought, but can't you simply access

App.User ?

I might have misunderstood the question of course.

查看更多
走好不送
3楼-- · 2019-08-07 09:56

in a controller you would use needs and then get it off the controller.

App.FooController = Ember.ObjectController.extend({
  needs:['userActions'],
  blah: function(){
    var userActionsModel = this.get('controllers.userActions.model');
  }
});

http://emberjs.jsbin.com/dofedehi/1/edit

查看更多
登录 后发表回答