lundi 12 novembre 2018

Create a fully dynamic table in EmberJS

I have defined a model in EmberJS with the following attributes:

import DS from 'ember-data';

export default DS.Model.extend({
    "name": DS.attr('string'),
    "status": DS.attr('string'),
    "email1": DS.attr('string'),
    "account_name": DS.attr('string'),
    "phone_work": DS.attr('string'),
    "date_entered": DS.attr('string'),
    "date_modified": DS.attr('string')
});

I am creating a component called fields-list that would render these attributes into a table (headers, body; just like a typical table to list some fields). However, instead of making the table bound to this model only, I want to make the component fully dynamic, so that other models with different field names could also reuse this component to generate their tables as well.

This way, whenever the component is used, it detects the model and populates the headers of the table as well as the body according to the fields in that model.

How do I achieve this? If there is anything that's not clear in the query please do let me know, I've tried my best to explain the issue properly as much as I can. Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire