Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending action to item controller from array controller

Tags:

ember.js

I have a simple ArrayController which has the itemController attribute defined. I'd like to send an action from the ArrayController to each item's backing controller. I'm not sure how to "bubble down" this action though.

like image 342
grouma Avatar asked Oct 02 '22 01:10

grouma


1 Answers

You can iterate over the controller itself and that returns the item controller.

App.IndexController = Em.ArrayController.extend({
  itemController: 'foo',
  actions:{
    talkToChildren:function(){
      this.forEach(function(itemController){
        itemController.send('foo');
      });
    }
  }
});

App.FooController = Em.ObjectController.extend({
  count: 1,
  actions:{
    foo:function(){
      this.incrementProperty('count');
    }
  }
})

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

like image 142
Kingpin2k Avatar answered Oct 13 '22 10:10

Kingpin2k