问题
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