This addon provides a very simple abstraction to use enum attributes with ember data. This addon has been very inspired by https://github.com/rmachielse/ember-enum
- Ember.js v3.16 or above
- Ember CLI v2.13 or above
- Node.js v10 or above
ember install ember-data-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:
See the Contributing guide for details.
This project is licensed under the MIT License.