Ember - 从控制器访问父路由的模型 [英] Ember - accessing parent route's model from controller

查看:173
本文介绍了Ember - 从控制器访问父路由的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个路由,让我们称他们/ user和/ user / actions。如何从UserActionsController方法访问用户模型?

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

我尝试过类似的操作:

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

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

但在这两种情况下,'modelFor'是未定义的而不是函数。

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

推荐答案

在控制器中使用需要 >

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

这篇关于Ember - 从控制器访问父路由的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆