lundi 2 novembre 2015

EmberJS: Get and set properties defined with dot notation

If I have a property defined with dot notation, how do I do an @get or @set on it in Ember?

model = DS.Model.extend EmberValidations.Mixin,
  ...

  validations:
    'user.fullName':
      presence:
        message: null

  initializer: (->
    @set 'validations.user.fullName.presence.message', @get('i18n').t('validations.fullName.format')
  ).on('init')

The problem is I can't do a @get or @set on 'validations.user.fullName' since it doesn't know how to access that property. But because of the way ember-validations works, I have to define the property that way, and I have to set it that way if I want to use i18n.

I can do @get('validations')['user.fullName'].presence.message to get the value if I need to, but really I need to set it.

I'm sure there must be a way to set it using dot notation in the property name, but I can't find anything anywhere saying how.

Any help please?




Aucun commentaire:

Enregistrer un commentaire