Permalink
Browse files

Added nextPath() to the controller and use it to step through posts.

chapter12-4
  • Loading branch information...
tmeasday committed Nov 27, 2013
1 parent 223c5e9 commit 6ff286c1b34378ae3037d19d082fb3e509bc12ec
Showing with 14 additions and 2 deletions.
  1. +5 −1 client/templates/posts/posts_list.html
  2. +9 −1 lib/router.js
@@ -3,5 +3,9 @@
{{#each posts}}
{{> postItem}}
{{/each}}
+
+ {{#if nextPath}}
+ <a class="load-more" href="{{nextPath}}">Load more</a>
+ {{/if}}
</div>
-</template>
+</template>
View
@@ -19,8 +19,16 @@ PostsListController = RouteController.extend({
waitOn: function() {
return Meteor.subscribe('posts', this.findOptions());
},
+ posts: function() {
+ return Posts.find({}, this.findOptions());
+ },
data: function() {
- return {posts: Posts.find({}, this.findOptions())};
+ var hasMore = this.posts().count() === this.postsLimit();
+ var nextPath = this.route.path({postsLimit: this.postsLimit() + this.increment});
+ return {
+ posts: this.posts(),
+ nextPath: hasMore ? nextPath : null
+ };
}
});

0 comments on commit 6ff286c

Please sign in to comment.