Infinite Scrolling in Iron Router based on Discover Meteor

强颜欢笑 提交于 2019-12-11 03:45:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!