lundi 10 juillet 2017

How to add additional information to ember models

I am looking to have additional data added onto my models after the JSON data is returned from the service. The service I talk to returns information as a code, but I want to also include a more readable name to display to users. This would be done almost everywhere the model is used.

Example:

Fetch from the service

{schedule: {code:'MONTHLY'}}

Have access to

{schedule: {code:'MONTHLY', name: 'Monthly'}}

This would be for things which have a map of code to name, where name only ever lives on the front end, and code is what is persisted. I see there is a concept of custom transforms, would this be the way to go?

I also plan to keep a mapping of all possible codes/names in another file, to iterate over or compare to the model's attributes. For instance I would want to present users with a choice of schedules to choose from, MONTHLY, QUARTERLY, or ANNUALLY.




Aucun commentaire:

Enregistrer un commentaire