jeudi 12 septembre 2019

emberjs model data null in template after normalizeResponse

I've trying to data from an api in to a template. But i cannot get the data into the template. i can see the model data in the serializer. The model object is just null

./app/routes/blogpost.js

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


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

./app/adapters/blogpost.js

import DS from 'ember-data';

export default DS.RESTAdapter.extend({
        host: 'http://localhost:5000',
        pathForType: function(modelName) {
                return "posts";
        }
});


./app/serializers/blogpost.js

import DS from 'ember-data';

export default DS.RESTSerializer.extend({
        /*normalizeResponse: function(store, primaryModelClass, payload, id, requestType) {

                let newPayload = {};
                newPayload[primaryModelClass.modelName] = payload;

                return this._super(store, primaryModelClass, newPayload, id, requestType) 
        }*/
});

./app/templates/blogpost.hbs

test








  
  




and the model ./app/models/blogpost.js

import DS from 'ember-data';
const { Model } = DS;

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

i can see in the browser that the xhr request is made and i also get the data. In the serializer the data is still there, but after that i cannot access the model attribute/object in the template.

the browser console only outputs null.

any ideaas where i've gone wrong?

thanks for any help.




Aucun commentaire:

Enregistrer un commentaire