流星全页刷新加载更多按钮(铁路由器)

Meteor full page refresh on load more button ( iron-router )

本文关键字:按钮 路由器 刷新 加载 流星      更新时间:2023-09-26

我的流星应用程序似乎在新路线上刷新,我添加了iron-router-progress,因为我在跟踪发现流星。

这里是URL - http://thusstyles.meteor.com/

Github URL - github.com/ThusStyles/diccoverMeteor

发现流星URL - http://meteor-book-chapter12-5.meteor.com/

当点击load more按钮时,我的页面似乎会跳到顶部

这是因为您使用了waitOn而不是订阅。waitOn将尝试呈现正在加载的模板,而subscriptions仍然会订阅,但不会触发正在加载的模板,因此不会导致闪烁。

但是,这也会在订阅准备好之前呈现页面。因此,您需要跟踪订阅的就绪状态。参见Discover Meteor的示例。注意,数据返回this.postsSub。

PostsListController = RouteController.extend({
template: 'postsList',
increment: 5,
postsLimit: function() {
return parseInt(this.params.postsLimit) || this.increment;
},
findOptions: function() {
return {sort: {submitted: -1}, limit: this.postsLimit()};
},
subscriptions: function() {
this.postsSub = Meteor.subscribe('posts', this.findOptions());
},
posts: function() {
return Posts.find({}, this.findOptions());
},
data: function() {
var hasMore = this.posts().count() === this.postsLimit();
var nextPath = this.route.path({postsLimit: this.postsLimit() + this.increm
ent});
return {
posts: this.posts(),
ready: this.postsSub.ready,
nextPath: hasMore ? nextPath : null
};
}
});

查看GitHub上的完整示例:https://github.com/DiscoverMeteor/Microscope/commit/chapter12-5