lundi 18 juin 2018

How to set Ember model default value when no data type specified?

How can I add a default value to an Ember model that does not have a data type specified.

import DS from 'ember-data'

export default DS.Model.extend({

  // with data type specified
  propertyString: DS.attr('string'),
  propertyWithDefault: DS.attr('number', {default: 0}),
  propertyWithFunctionDfault: DS.attr('date', {
      defaultValue() { return new Date() }
  }),

  // How to set default when no type defined
  propertyNoType: DS.attr(),
  propertyNoTypeWithDefault: DS.attr(null, {default: 0}) // does not work

})

https://guides.emberjs.com/release/models/defining-models/#toc_options




Aucun commentaire:

Enregistrer un commentaire