Getting data from rest API and Do Pagination


#1

HI everybody,
I have requirement like . getting json data as response from rest api and do pagination on those values.
And those values we are not going to save in mongodb. If we are saving json values to mongodb . i am able to do pagination using Alethes:pages plug in. With out saving data to mongodb I am not able to do pagination.

Can anybody help on this.

Thanks,
Niladri Rout


#2

Maybe save the data to a local collection?

APIResponse = new Mongo.Collection(null);


#3

I tried using new Mongo.Collection(null). but its not working .


#4

So something like…

export const Pages = new Mongo.Collection('pages'); // client only collection.

export class PaginatedList extends BlazeComponent {
  onCreated() {
    super.onCreated();

    FlowRouter.setQueryParams({
      perPage: 10
    });

    this.autorun(() => {
      this.subscribe('pages', FlowRouter.getParam('page'), {
        perPage: FlowRouter.getQueryParam('perPage')
      });
    });
  }
}

Then you can make a fancy publication that adds “pages”.

Meteor.publish('pages', function (page, options) {
  check(page, Number);
  check(options, Match.ObjectIncluding({
    perPage: Number
  }));

  const observer = YourCollection.find({}, {
    skip: page * options.perPage,
    limit: perPage
  }).observe({
    added: doc => this.added('pages', doc._id, Object.assign(doc, { page: page }))
  });

  this.ready();
  this.onStop(() => observer.stop());
});

#5

HI corvid,
I am new to meteor. I am not able to understand which code to write where. can u give me some git hub repository so that i can check that. Or is there any way that u can show me one sample example

Thanks for your time