流星js定制分页
问题描述:
我恳请需要支持。我已经按照YouTube教程编写了分页,除了再次回退之外,该教程还可以正常工作。它只有2个按钮,previous
和next
,当点击下一个按钮时,它可以正常工作,但前一个按钮只向后退一次。假设我在分页集合中有20条记录一次显示5个,下一个按钮可以到达第四个页面的结尾,但上一个按钮不会向后传递一个。请问我该怎么做分页体验?只要用户点击,上一个按钮就会导航到最后一页。流星js定制分页
活动的分页按钮:
Template.myviews.events({
'click .previous': function() {
if (Session.get('skip') > 5) {
Session.set('skip', Session.get('skip') - 5);
}
},
'click .next': function() {
Session.set('skip', Session.get('skip') + 5);
}
});
公开:
Meteor.publish('userSchools', function (skipCount) {
check(skipCount, Number);
user = Meteor.users.findOne({ _id: this.userId });
if(user) {
if(user.emails[0].verified) {
return SchoolDb.find({userId: Meteor.userId()}, {limit: 5, skip: skipCount});
} else {
throw new Meteor.Error('Not authorized');
return false;
}
}
});
订阅:
Session.setDefault('skip', 0);
Tracker.autorun(function() {
Meteor.subscribe('userSchools', Session.get('skip'));
});
大火分页按钮:
<ul class="pager">
<li class="previous"><a href="#">Previous</a> </li>
<li class="next"><a href="#">Next</a> </li>
</ul>
模板帮手:
RenderSchool: function() {
if(Meteor.userId()) {
if(Meteor.user().emails[0].verified) {
return SchoolDb.find({userId: Meteor.userId()}).fetch().reverse();
} else {
FlowRouter.go('/');
Bert.alert('Please verify your account to proceed', 'success', 'growl-top-right');
}
}
}
答
你有6个文件总计每页2个文档,共有3页。
你if
条件previous
按钮单击处理程序阻止你去到第一页:
if (Session.get('skip') > 2 /* testing */) {
...
}
对于skip
第2页将等于2
,并在下次点击这个条件会false
,来自回去预防。
当你在第三页上时 - 你可以仅在第二页上创建一个按钮只能工作一次的印象。
它应该是这样的:
if (Session.get('skip') > 0) {
...
}
你能证明模板和帮助呢? – Styx
THanks,Styx,我已经更新了代码,添加了帮手。 – kehinde
你的收藏中有多少物品? – Styx