samedi 2 septembre 2017

need to call Action twice to return data from Computed Property in Ember

I have a computed property that retrieves data from related models off of a ember light table, where the related model fields are stored in an idFields array. I'm calling the function filterTableRow from within a cell when a user pushes the button that has the action attached. In order for it to get the id values, you have to call the function twice; the first time, null is returned. How do I fix this?

idMapping: Ember.computed('row', 'value', 'column', 'idFields', function () {
  let row = this.get('row');
  let idFields = this.get('idFields');
  let idObj = [];
  mediaFields.map((field) => {
    let fieldValue = this.get(`column.${field}`) ? this.get(`column.${field}`): row.get(field);
    if (fieldValue) {
      idObj.pushObject({name: field, data: fieldValue});
    }
  );
  return idObj || [];
}),

filterTableRow() {
  let idMapping = this.get('idMapping');
  alert(idMapping.mapBy('data').mapBy('id'));
}




Aucun commentaire:

Enregistrer un commentaire