This addon provides a very simple abstraction to use enum attributes with ember data.
ember install ember-enum
You can define an enum attribute as follows:
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default Model.extend({
status: attr('enum', {
options: [
'started',
'stopped'
],
defaultValue: 'started'
})
});
The value from the json response is expected to be a string. Now you can use the attribute in templates:
You can also use boolean methods to check if the enum has a certain value:
You can use a select element like this:
This project only works with ember-data 2.5 and higher.
This project is released under the MIT License.