la_m3a
Last Updated: February 25, 2016
·
1.874K
· ghedamat

add support for basic "array/raw" type to EmberData

It can be useful to have support for an Array type in EmberData,
in my actual use case the API is returning a nested array that I have to represent as a table.

Adding support for this kind of data is super easy:

App.RESTAdapter.registerTransform('array',{
  deserialize: function(data){
    if (data)
      return data;
    return null;
  },

  serialize: function(array){
    return array;
  }
});

A more comprehensive implementation can be found here:
http://stackoverflow.com/questions/12168570/how-to-represent-arrays-within-ember-data-models/14842514#14842514

As noted in the stackoverflow answers this transform can be used for any kind of "raw" data