Skip to content

Instantly share code, notes, and snippets.

@jerel
Last active August 29, 2015 14:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerel/16a07356c53d4daa03d6 to your computer and use it in GitHub Desktop.
Save jerel/16a07356c53d4daa03d6 to your computer and use it in GitHub Desktop.
Ember 1.7 comment pagination example extracted from a working app
import Ember from 'ember';
export default Ember.ObjectController.extend({
queryParams: ['page'],
page: 1,
comments: Ember.K(),
paginationObserver: function() {
var id = this.get('id'),
page = this.get('page'),
comments = this.store.find('comment', {post: id, page: page});
this.set('comments', comments);
}.observes('page', 'model') // fetch comments when the page changes and get the first page when `model` is set
});
// post.hbs
{{postTitle}}
{{postBody}}
{{#each comment in comments}}
{{comment.author}}
{{comment.body}}
{{else}}
There are no comments.
{{/each}}
{{#if comments.content.meta}}
{{#if comments.content.meta.previous}}
// this could also be an action that just changed the value of `page`
{{link-to 'Previous' 'post' (query-params page=comments.content.meta.previous) }}
{{/if}}
{{#if comments.content.meta.next}}
{{link-to 'Next' 'post' (query-params page=comments.content.meta.next) }}
{{/if}}
{{/if}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment