dimanche 25 septembre 2016

Ember data fetch json file

I'm trying to get data from json file from server. My code:

adapters/application.js:

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
    host: 'http://exampleweb.com',
    namespace: 'file.json'
});

models/item.js

import DS from 'ember-data';

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

routes/index.js

import Ember from 'ember';

export default Ember.Route.extend({
    model() {
        return this.get('store').findAll('item');
    }
});

templates/application.hbs


<br>


JSON file on server look like this:

{
  "Products": [
  {
    "name": "Aviator"
  },
  {
    "name": "Dark"
  }]
}

Now ember requst http://ift.tt/2dhpHfr. How can I get this Products correctly and display them in template?




Aucun commentaire:

Enregistrer un commentaire