问题
I can't seem to get the infinite scrolling to work from Commit 12-5. It says just to mrt add iron-router-progress
and everything should work, but my page keeps refreshing. Here's what I'm working with:
PostsListController = RouteController.extend({
template: 'blog',
increment: 20,
limit: function() {
return parseInt(this.params.postsLimit) || this.increment;
},
waitOn: function() {
return Meteor.subscribe('posts', this.limit());
},
posts: function() {
return Posts.find({}, {
limit: this.limit()
});
},
data: function() {
var hasMore = this.posts().count() === this.limit();
var nextPath = this.route.path({
postsLimit: this.limit() + this.increment
});
return {
posts: this.posts(),
nextPath: hasMore ? nextPath : null
};
}
});
Router.map(function() {
this.route('blog', {
path: '/:postsLimit?',
controller: PostsListController
})
})
Router.configure({
layoutTemplate: 'layout',
notFoundTemplate: 'notFound',
});
Everything seems to work EXCEPT when I click load more, the page blinks and jumps back up to the top!
回答1:
As you can read in the GitHub issues related the commit, it is actually a bug in the 0.7.1 version of iron-router. With the version they used (look up the smart.lock file) it won't refresh and go to the top.
来源:https://stackoverflow.com/questions/23902891/infinite-scrolling-in-iron-router-based-on-discover-meteor