mercredi 23 mars 2016

Ember 2.0 : why my action is not triggered in route

I am trying to move a test app from Ember 1.0 to Ember 2.0

I wrote an index template, with an action event 'alert'

<table id="t01">
      <tr>
        <th>Company Name</th>
      </tr>
      {{#each model as |item|}}
        <tr>
          <td {{action "alert" "alert form company name" }}>{{item.name}}</td>
        </tr>
      {{/each}}
</table>

I wrote an application.js controller to initialise the properties

import Ember from 'ember';
export default Ember.Controller.extend({
  className:"hide",
  message: ""
});

I also have an index.js controller to perform some logic at the index controller level

import Ember from 'ember';
export default Ember.Controller.extend({
  actions:{
    alert: function(){
      console.log("do some controller level processing");
      return true;
    } 
  }
});

and finally I have a routes/application.js with an 'alert' event handler defined, to update the application controller properties ( className , message)

import Ember from 'ember';
export default Ember.Route.extend({
  actions:{
    alert: function(message){
      var applicationController = this.controllerFor("application"); 
      applicationController.set("className","alert"); 
      applicationController.set("message",message);
      Ember.run.later(function(){
        applicationController.set("className","hide");
      },2000);
    }
  }
});

and a routes/index.js to serve the model data

but it's not working correctly in Ember.js 2.0 ( running 2.4.2) and there is no error message in the console, I only get the index controller console log output

it seems that the alert action in the routes/application.js is triggered, receiving correctly the message , but the properties are not set... can I get the application controller ? with

var applicationController = this.controllerFor("application");

thanks for feedback




Aucun commentaire:

Enregistrer un commentaire