Skip to content Skip to sidebar Skip to footer

Emberdata 1.0.0

I'm using Laravel 4 with emberjs and I need to list a collection of relationship data on emberjs app, but L4 print collection a little bit different, and so, I am trying to change

Solution 1:

Really the only problem with the json for what you're doing so far is the array of square ids.

"squares":[{"id":"1"}]

Ember Data is expecting

"squares":["1"]

This can easily be remedied down the path you were taking

App.NameSerializer = DS.RESTSerializer.extend({
    primaryKey: 'id', // note this isn't necessary, the primary key is id by default
    extractArray: function(store, type, payload, id, requestType) {
      payload.names.forEach(function(name){
        var validSquareIdArray = [];
        name.squares.forEach(function(square){
          validSquareIdArray.push(square.id);
        });
        name.squares = validSquareIdArray;
      });

        return this._super(store, type, payload, id, requestType);
   }
});

http://emberjs.jsbin.com/OxIDiVU/279/edit

Post a Comment for "Emberdata 1.0.0"