jeudi 12 novembre 2015

Ember.js: How to access JSON API metadata from store.findRecord call

I am currently trying to figure out how to access metadata when using the store.findRecord() call.

In the guides (http://ift.tt/1SmaJht) it says that metadata can be accessed by doing the following:

store.query('post').then((result) => {
  let meta = result.get('meta');
})

I was hoping this would work when using findRecord as well

store.findRecord('book', params.id, {adapterOptions: {query: params}}).then((result) => {
    let meta = result.get('meta');
})

However this always returns undefined for the meta property. I'm assuming that metadata is not being set when using findRecord. I am returning valid JSON-API with a meta property at the top level like this:

{
  "meta": {
    "page": {
      "number": 1,
      "size": 100,
      "total": 20
    },
   "data":[
       // data here
    ]
  }
}

Is there a way to access the metadata returned by the server when using findRecord() and the JSONAPISerializer and JSONAPIAdapters?

Thank you!

I am using the following versions:

Ember             : 2.1.0
Ember Data        : 2.1.0
jQuery            : 1.11.3




Aucun commentaire:

Enregistrer un commentaire