Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found a cleaner approach for extracting meta information from the server response with ember-data.</p> <p>We have to tell the serializer which meta-information to expect (in this case pagination):</p> <pre><code> App.serializer = DS.RESTSerializer.create(); App.serializer.configure({ pagination: 'pagination' }); App.CustomAdapter = DS.RESTAdapter.extend({ serializer: App.serializer }); App.Store = DS.Store.extend({ adapter: 'App.CustomAdapter' }); </code></pre> <p>After that every time the server sends a meta-property with a pagination object this object will be added to the store's <code>TypeMaps</code> property for the requested Model-Class. </p> <p>For example with the following response:</p> <pre><code> { 'meta': {'pagination': { 'page': 1, 'total': 10 } }, 'posts':[ ... ] } </code></pre> <p>The <code>TypeMap</code> for the App.Post-Model would include the pagination object after the posts have loaded.</p> <p>You can't observe the TypeMaps-property of the store directly so I added an computed property to the PostsController to have access to the requests pagination meta information:</p> <pre><code> App.PostsController = Ember.ArrayController.extend({ pagination: function () { if (this.get('model.isLoaded')) { modelType = this.get('model.type'); this.get('store').typeMapFor(modelType).metadata.pagination } }.property('model.isLoaded') }); </code></pre> <p>I really don't think that's a great solution to the meta information problem but this is the best solution I was able to come up with yet with Ember-Data. Maybe this will be easier in the future.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload