jeudi 22 février 2018

EmberJS parsing data from RESTful api

I'm new to Ember and I keep studying and learning every day. And as a challenge, I'm having great difficulty getting data from the RESTful API pokeapi.co I want to get the names and url of the results https://pokeapi.co/api/v2/pokemon/ to then pass the ID as a parameter and get all data in https://pokeapi.co/api/v2/pokemon/1/ /2 /3 etc.

I'm stuck, please help me.... My Code:

adapter/pokemon.js

import DS from 'ember-data';

export default DS.RESTAdapter.extend({
    host:'https://pokeapi.co',
    namespace: 'api/v2',

    pathForType(){
        return 'pokemon';
    }
});

model/pokemon.js

import DS from 'ember-data';

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

routes/pokemon.js

import Route from '@ember/routing/route';

export default Route.extend({
    model(){
        return this.store.findRecord('pokemon')
//    setupController(controller, model){
//    controller.set('pokemons',model);
    }
});

serializer/pokemon.js

import DS from 'ember-data';

export default DS.RESTSerializer.extend({

    normalizeResponse(store, primaryModelClass, payload, id, requestType){
        payload = {
            pokemon: payload
        },
        console.log(payload);
        return this._super(store, primaryModelClass, payload, id, requestType);
   }
});

templates/pokemon.hbs


      <div class="md-list-item-text">
         <h3>#: </h3>
        </div>





Aucun commentaire:

Enregistrer un commentaire