Accessing meta information passed in a json server response

后端 未结 3 939
一整个雨季
一整个雨季 2020-12-23 10:46

I am using the Ember-Data Rest-Adapter and the JSON returned from my server looks basically like the one in the Active Model Serializers Documentation

{
  \"         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-23 10:53

    I think the immediate fix for you would be to attach totalCount to your model(recordArray), see this thread.

    Another way to go would be to create your own adapter:

    DS.Adapter.create({
      find: function (store, type, id) {
        $.ajax({
          url:      type.url,
          dataType: 'jsonp',
          context:  store,
          success:  function(response){
            this.load(type, id, response.data);
          }
        });
      },
      findAll: function(store, type) {
        $.ajax({
          url:      type.url,
          dataType: 'jsonp',
          context:  store,
          success:  function(response){
            this.loadMany(type, response.data);
          }
        });
      }
    });
    

    Response parameter in success callback in findAll method, should be an object that you need:

    response: {
      meta: {
        totalCount: 10
      },
      posts: [{}, {}]
    }
    

    Hope this helps.

提交回复
热议问题