Non-persistent attributes in EmberJS

后端 未结 4 1248
时光取名叫无心
时光取名叫无心 2021-02-13 19:48

Does anyone know of a way to specify for an Ember model an attribute which is not persisted?

Basically, we\'re loading some metadata related to each model

4条回答
  •  悲哀的现实
    2021-02-13 20:39

    The other answers to this question work with Ember data versions up to 0.13, and no longer work. For Ember data 1.0 beta 3 you can do:

    App.ApplicationSerializer = DS.RESTSerializer.extend({
      serializeAttribute: function(record, json, key, attribute) {
        if (attribute.options.transient) {
          return;
        }
        return this._super(record, json, key, attribute);
      }
    });
    

    Now you can use transient attributes:

    App.User = DS.Model.extend({
      name: DS.attr('string', {transient: true})
    });
    

    These attributes won't be sent to the server when saving records.

提交回复
热议问题