Last active
August 29, 2015 14:05
-
-
Save jerel/16a07356c53d4daa03d6 to your computer and use it in GitHub Desktop.
Ember 1.7 comment pagination example extracted from a working app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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