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

How Ember determines that model has changed?

$
0
0

@marat93 wrote:

In my Ember app I have a page with the list of posts. This posts come from API. Here is my model.

import Ember from 'ember';

export default Ember.Route.extend({
  queryParams: {
    order: {
      refreshModel: true
    }
  },

  model(params) {
    return this.store.query('design', params);
  }
});

I want to sort post on API, so I add query parameter order to my request. API responds with the same posts but in different order. Here are my requests.

GET http://localhost:3000/api/v1/posts?order=title-desc

{
	"data": [{
		"id": "247",
		"type": "posts",
		"attributes": {
			"title": "Randy McCullough",
			"created-at": "2015-11-13T09:43:56.147Z"
		}
	}, {
		"id": "248",
		"type": "posts",
		"attributes": {
			"title": "Pablo Carter"
			"created-at": "2015-11-13T09:43:56.248Z"
		}
	}
	}]
}

GET http://localhost:3000/api/v1/posts?order=title-asc

{
	"data": [
       {
		"id": "248",
		"type": "posts",
		"attributes": {
			"title": "Pablo Carter"
			"created-at": "2015-11-13T09:43:56.248Z"
		}
	},
       {
		"id": "247",
		"type": "posts",
		"attributes": {
			"title": "Randy McCullough",
			"created-at": "2015-11-13T09:43:56.147Z"
		}
	}, 
	}]
}

Here is my template.

{{#each posts as |post|}}
  {{post-thumbnail post}}
{{else}}
  No posts was found.
{{/each}}

Problem is that template doesn't re-render after sorting. I think Ember doesn't account order of elements in response and consider that responses as identical.

May be the whole way of sorting I use is wrong? What is the best practice of sorting in Ember?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4841