vendredi 26 juin 2015

Ember Data has undefined properties from JSON API response

Ember and javascript newbie. Sorry.

ember.debug.js:5361DEBUG: Ember      : 1.13.2
ember.debug.js:5361DEBUG: Ember Data : 1.13.1
ember.debug.js:5361DEBUG: jQuery     : 1.11.3

I'm using ember-json-api,

npm install --save-dev ember-json-api

"ember-json-api": "^0.5.0",

I've set up the adapter, adapter/application.js

import JsonApiAdapter from 'ember-json-api/json-api-adapter';

export default JsonApiAdapter.extend({
    namespace: "api"
});

I've set up the serializer, serializer/application.js

import JsonApiSerializer from 'ember-json-api/json-api-serializer';
export default JsonApiSerializer;

I've set up a model, models/competitions.js

import DS from 'ember-data';

export default DS.Model.extend({
    name: DS.attr('string'),
    imageUri: DS.attr('string'),
    ord: DS.attr('integer')
});

I've set up a mock, server/mocks/competitions.js

 competitionsRouter.get('/', function(req, res) {
    res.send({
      "data": [
          {
              "type": "competition",
              "id": "10",
              "attributes":
                  {
                      "ord": 1,
                      "name": "Competition Mock 2015",
                      "imageUri": "http://localhost/Pictures/1"
                  }
          },
          {
              "type": "competition",
              "id": "11",
              "attributes":
                  {
                      "ord": 2,
                      "name": "Competition Mock 2014",
                      "imageUri": null
                  }
          }
      ]
  });

When I call my competitions route the ember inspector is displaying in the data section that there are two competition objects and it correctly displays their Id values of 10 & 11 but the name, imageUri and ord properties are all listed as undefined.

Is my mock returning the data in the correct format? If so, what am I missing ?




Aucun commentaire:

Enregistrer un commentaire