mercredi 1 juillet 2015

Sending an action from a child component and catching it in a parent component

Ember: 1.13.2

I can't seem to get this working.

Parent/child widget (gridster-container/gridster-widget)

{{#gridster-container}}
    {{#each model as |widget|}}
        {{#gridster-widget sizeX=widget.sizeX sizeY=widget.sizeY action="addWidget"}}

           ...

        {{/gridster-widget}}
    {{/each}}
{{/gridster-container}}

gridster-widget

export default Ember.Component.extend({
  tagName : 'li',
  sizeX : 1,
  sizeY : 1,

  widget : null,

  didInsertElement : function() {
    var sizeX = this.get('sizeX');
    var sizeY = this.get('sizeY');
        //this.get('parentView').addWidget(this, sizeX, sizeY);
    //this.send('addWidget', this, sizeX, sizeY);
    //this.sendAction('action', this, sizeX, sizeY);
    //this.attrs.action(this, sizeX, sizeY);
    //this.get('gridsterContainer').send('addWidget', this, sizeX, sizeY);
    //this.action(this, sizeX, sizeY);
    this.sendAction('action', this, sizeX, sizeY); //I can see this executing in the debugger.
    }

});

In the gridster-container component I have the following action to capture the action.

  actions : {
    addWidget : function(widget, sizeX, sizeY) {
      alert('worket'); //This is never called
    }
  },

However the action is never called.




Aucun commentaire:

Enregistrer un commentaire