0

I have a model in Ember with two actions/components associated. The first, runQuery, queries the store and retrieves results. The second downloadCSV should ideally take the model attributes headers and rows (generated and formatted from PapaParse) and export it as a csv when a button is clicked.

runQuery(id, uid) {
  const queryData = {id, uid};

  this.store.find('queryResult', queryData).then( results => {
    let result = results.toArray().get(0);
    this.set('controller.model.result', result);
    this.set('controller.model.headers', results.content[0]._data.headers);
    this.set('controller.model.rows', results.content[0]._data.rows);

  });
},

downloadCSV(headers, rows) {
  exportCSV(headers, rows)
}

I'm using an emblem template to pass the csvData back to the download CSV method:

csv-data action="downloadCSV" headers=model.headers rows=model.rows

But when I try to run the method, the headers and rows always undefined despite being accessible in the template. (I can see it on the page with {{model.headers}}/ {{model.rows}} and iterate over them to display a table using emblem's each method)

I see that Ember Data models do not support complex object types. Is there a way I can make the header and row objects globally accessible after they are generated so the download data method can properly consume them?

BarFooBar
  • 1,086
  • 2
  • 13
  • 32
  • Do you have the properties `headers` and `rows` defined on your model as an `attr()`? – nem035 Mar 12 '16 at 00:01
  • Yes. I'll specify in the question. – BarFooBar Mar 12 '16 at 00:01
  • I'm not familiar with emblem syntax, is there a specific reason you are using it instead of the recommended HTMLBars that are shipped with ember? Can you explain what this emblem snippet is supposed to do? Are you defining a component called `csv-data` and passing parameters: string `action` and arrays `headers` and `rows` to it? Regardless, at which point are you passing the arguments `headers` and `rows` into the action `downloadCSV` and where are you calling this action? – nem035 Mar 12 '16 at 00:49

0 Answers0