jeudi 30 juin 2016

Ember - Adding dynamic attributes to model inside serializer

How can we add dynamic attributes to model inside serializer.

I have created a model entity. I need this model for different type of entities. So for now I created an attribute type to identify which type of entity is that and the remaining attributes I need to create dynamically based on the response in serializer response handler. Is it possible?

entity.js

export default DS.Model.extend({
   type: DS.attr('string')
});

entity.js(Serialaizer)

export default DS.RESTSerializer.extend({
   normalizeFindAllResponse(store, primaryModelClass, payload) {
      var payloadData = {};
      payloadData.data = [];    
      payload.forEach(function(model) {
          // I will get the entity type and other attributes here
          // How can I define new attribute for model entity here
      }
   }




Aucun commentaire:

Enregistrer un commentaire