Last Updated: February 25, 2016
·
2.248K
· 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

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside