I'm trying to put a property in my Ember(ember-data) models that is just an array of the properties to include in a generic table component. At first I just added this to my models:
tableColumns: function() {
return ['age', 'gender', 'whatever'];
}.property()
But now I find myself jumping through hoops in the child components to easily iterate through these these properties and call their values for each model instance.
Since the columns will change with each model I thought this was a good solution. Is there a better way?
I'm getting stuck in particular when for each row(model instance) I want to just say something unreasonable like the below imaginary snippet.
{{#each col in tableColumns}}
<td>{{model.col}}</td>
{{/each}}
I'm trying to stay controller-free and keep my components generic.
EDIT:
Right now in the row component I'm doing this and then iterating through 'cols' in the hbs. But it doesn't feel right and I'm getting to the async part(some of the columns need to make an external call) that I think will cause some problems so I wanted to find a better way.
this.get('model').tableColumns().forEach(function(cell){
cols.push(that.get('model._data.' + cell));
});