Accessing Multiple Models with One Action

假装没事ソ 提交于 2019-12-24 03:52:46

问题


I have multiple models within my index route which I declared like so:

App.IndexRoute = Em.Route.extend({
  model: function(){   
   return Ember.RSVP.hash({
     dogs: this.store.find('dog'),
     cats: this.store.find('cat')
  })
})

And I'm able to render them fine by doing this:

<script type="text/x-handlebars" data-template-name="index">
  {{render 'dogs' dogs}}
  {{render 'cats' cats}}
</script> 

The problem I am facing now, is that I want to pass a single action from the index to specific actions on each of these models controllers. I've tried this:

App.IndexController = Em.ObjectController.extend({
  needs: ['cats', 'dogs'],  
  actions: {   
    indexAction: function() {      
      this.get('controllers.cats').send('catAction')
      this.get('controllers.dogs').send('dogAction')
    }
  }
})

Which calls the appropriate functions but these function use the this keyword which is seems to be bound differently when called directly.

Does anyone have any suggestions?

来源:https://stackoverflow.com/questions/21095364/accessing-multiple-models-with-one-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!