Using JSONAPI::Resources, I've configured the default paginator in Rails. When I hit my /posts end point from ember I get a response like:
{
"data": [
{
"id": "1",
"type": "posts",
"links": {
"self": "http://localhost:3000/posts/1"
},
"attributes": {
"title": "My First Post!",
"author": "josh",
"body": "I love blogging.",
"created-at": "2016-07-31T05:29:13.000Z",
"updated-at": "2016-07-31T05:29:13.000Z"
},
"relationships": {
"comments": {
"links": {
"self": "http://localhost:3000/posts/1/relationships/comments",
"related": "http://localhost:3000/posts/1/comments"
}
}
}
},
{
...
}
],
"links": {
"first": "http://localhost:3000/posts?page%5Bnumber%5D=1&page%5Bsize%5D=10",
"next": "http://localhost:3000/posts?page%5Bnumber%5D=2&page%5Bsize%5D=10",
"last": "http://localhost:3000/posts?page%5Bnumber%5D=12&page%5Bsize%5D=10"
}
}
I want to implement pagination now in my Ember app. I'm thinking one way to do this would be to attach an action to my "Next" link in the template. In routes/posts.js I've found I can get at the top-level links object with something like this:
actions: {
nextPage: function() {
var nextLink = this.store.query('post', {}).then(result => {
console.log(result.get('links.next'));
});
}
}
But I'm not exactly sure what to do with it after this point. I can't transitionTo this url (its the api endpoint). Where do I go from here?
Aucun commentaire:
Enregistrer un commentaire