@johnunclesam wrote:
I use very often in my code:
{{#each model.posts as |post|}} <div>post.title</div> {{else}} <div>Loading the posts...</div> {{/each}}
But sometimes I don't know if the
model.posts
is empty or not.How to show a message instead of loading forever an empty array?
The problem here is that I'm in
/category/2
page, so incategory.hbs
template and posts are "sideloaded" in response, like this:{ "data": { "id": "1", "type": "categories", "attributes": { "name": "Books" }, "relationships": { "posts": { "data": [{ "id": "14", "type": "posts" }, { "id": "15", "type": "posts" }, { "id": "20", "type": "posts" }] } } }, "included": [{ "id": "14", "type": "posts", "attributes": { "commented": true, "comments": 10 } }, { "id": "15", "type": "posts", "attributes": { "commented": false, "comments": 10 } }, { "id": "20", "type": "posts", "attributes": { "commented": false, "comments": 10 } }] }
I'm using ember-data and my models are:
category
name: DS.attr('string'), posts: DS.hasMany('post')
post
commented: DS.attr('string'), comments: DS.attr('number'), category: DS.belongsTo('category')
Maybe I will create an ember-twiddle, I'm having problem to simulate my problem with ember-data on ember-twiddle...
Posts: 5
Participants: 2