Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4830

Ember data - content object doesn't show any data

$
0
0

@traskat wrote:

Hey,

i have the problem that i cannot access my model data

./app/adapters/blogpost.js: import DS from ‘ember-data’;

export default DS.RESTAdapter.extend({
	host: "http://localhost:1337",
	namespace: "Blogposts",
	pathForType(modelName) {
		return "";
	}
});

./app/models/blogpost.js import DS from ‘ember-data’; const { Model } = DS;

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

./app/components/blogpost.js import Component from ‘@ember/component’; import Ember from ‘ember’;

export default Component.extend({
	blogposts:  Ember.inject.service('blogpost'),
});

./app/services/blogpost.js

import Service from '@ember/service';
import Ember from 'ember';
let data = {
	id : 0,
	headline : "headline 1",
	postText: "post first text"
}

export default Service.extend({
	blogposts: null,
	store: Ember.inject.service('store'),
	init() {
		console.log('*********')
		this.set('blogposts', this.store.findAll('blogpost'))
		//this.set('blogposts',data)
	}
});

./app/serializers/blogpost.js import DS from ‘ember-data’;

export default DS.RESTSerializer.extend({
	normalizeResponse(store, primaryModelClass, payload, id, requestType){
		let tmpPayload = {
			blogposts: payload
		}

		console.log('----------------------!',tmpPayload)

		return this._super(store, primaryModelClass, tmpPayload, id, requestType);
		//return tmpPaylod
	}
});

./app/templates/bogpost.hbs

blogposts
{{log this}}

{{log blogposts.blogposts}}


{{#each blogposts.blogposts.content.content as |post|}}
	{{post.blogposts.id}} <br />
	{{post.headline}}<br />
	{{post.post}} <br />
{{/each}}
{{yield}}

For some reason i cannot access the data in the template, but if i check in the console of the browser. there are only objects in the content field. No actual data. See in the picture

The data itself is accessable in the serializer

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4830

Trending Articles