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?