How to use links to break into json-api in Ember 2.x?

I am currently working on an application using the Rails (4.1.0) API and Ember (2.1.0), and it is difficult for me to paginate in Ember's works.

Rails API JSON output includes automatically made links to pages (from a combination of the JSON API adapter in AMS and Kaminari pagination) as follows:

"links": {
    "self": "http://example.com/articles?page[number]=3&page[size]=1",
    "first": "http://example.com/articles?page[number]=1&page[size]=1",
    "prev": "http://example.com/articles?page[number]=2&page[size]=1",
    "next": "http://example.com/articles?page[number]=4&page[size]=1",
    "last": "http://example.com/articles?page[number]=13&page[size]=1"
  }

Can someone give me a hint on how to get to these values ​​in Ember-Data to use them in an Ember template? Has anyone found a temporary workaround for this problem (since Ember is likely to be fully compatible with the JSON API one day)?

Any help would be greatly appreciated;)

Link to the combination of the JSON API adapter in the AMS and Kaminari pages: https://github.com/rails-api/active_model_serializers/blob/master/docs/howto/add_pagination_links.md

Edit:

After some progress on this question, I think it’s better to ask now:
How do I pass a hash like page: { number: x, size: y }in params in an Ember Rails API request?

+4
source share
1 answer

Ember calls this data that describes the payload: meta / metadata. Hope this helps in future searches.

You just need to create a Serializer that intercepts the payload from the server and moves response.links to the Ember Data metadata.

Ember : http://guides.emberjs.com/v2.1.0/models/handling-metadata/

Ember Data API extractMeta : http://emberjs.com/api/data/classes/DS.JSONAPISerializer.html#method_extractMeta

, API JSON, , , response.meta.

https://github.com/rails-api/active_model_serializers/blob/master/docs/howto/add_pagination_links.md#json-adapter

+1

Source: https://habr.com/ru/post/1611411/


All Articles