Pagination 分页meteor publish不返回记录
我肯定知道这段代码有问题,但无法找到正确的方法来完成它。我想在显示学生的页面上分页。如果我简单地这样说Pagination 分页meteor publish不返回记录,pagination,publish-subscribe,meteor-blaze,meteor-helper,Pagination,Publish Subscribe,Meteor Blaze,Meteor Helper,我肯定知道这段代码有问题,但无法找到正确的方法来完成它。我想在显示学生的页面上分页。如果我简单地这样说返回SchoolStudents.find(),它通过返回所有学生来完美工作,但这违背了分页的主要目的。我要么不确定问题在哪里,要么在发布函数中,要么在帮助函数中。我想要实现的是,学生学院的记录应该分页,以便在一页上显示2条记录 这是自动运行 Session.setDefault('skip', 0); Template.view.onCreated(function () { Sess
返回SchoolStudents.find()代码>,它通过返回所有学生来完美工作,但这违背了分页的主要目的。我要么不确定问题在哪里,要么在发布函数中,要么在帮助函数中。我想要实现的是,学生学院的记录应该分页,以便在一页上显示2条记录
这是自动运行
Session.setDefault('skip', 0);
Template.view.onCreated(function () {
Session.setPersistent('ReceivedSlug', FlowRouter.getParam('myslug'));
this.autorun(function () {
Meteor.subscribe('SchoolStudents', Session.get('skip'));
});
});
这是helper方法
students(){
let myslug = trimInput(Session.get('ReceivedSlug'));
if (myslug) {
let mySchoolDoc = SchoolDb.findOne({slug: myslug});
if (mySchoolDoc) {
let arrayModuleSchool = StudentSchool.find({schoolId: mySchoolDoc._id});
if (arrayModuleSchool) {
var arrayStudentIds = [];
arrayModuleSchool.forEach(function(studentSchool){
arrayStudentIds.push(studentSchool.studentId);
});
let subReadiness = SchoolStudents.find({_id: {$in: arrayStudentIds}}).fetch();
if (subReadiness) {
return subReadiness;
}
}
}
}
}
这是发布方法
Meteor.publish('SchoolStudents', function (skipCount) {
check(skipCount, Number);
user = Meteor.users.findOne({_id:this.userId})
if(user) {
if(user.emails[0].verified) {
return SchoolStudents.find({userId: this.userId}, {limit: 2, skip: skipCount});
} else {
throw new Meteor.Error('Not authorized');
return false;
}
}
});
火焰模板
<section class="tab-section" id="content4">
{{#each student in students}}
<div class="row" style="margin-top: -20px;">
<!-- Begin Listing: 609 W GRAVERS LN-->
<div class="brdr bgc-fff pad-10 box-shad btm-mrg-20 property-listing card-1">
<div class="media">
<div class="media-body fnt-smaller">
<a href="#" target="_parent"></a>
<h4 class="media-heading"><a href="/student/{{student.slug}}" target="_parent">{{student.firstname}} {{student.lastname}}</a></h4>
<p class="hidden-xs" style="margin-bottom: 5px; margin-top: -10px;">{{trimString student.useremail 0 110}}</p><span class="fnt-smaller fnt-lighter fnt-arial">{{course.createdAt}}</span>
</div>
</div>
</div><!-- End Listing-->
</div>
{{/each}}
<ul class="pager">
<li class="studentprevious"><a href="">Previous</a> </li>
<li class="studentnext"><a href="">Next</a> </li>
</ul>
</section>
我遇到了与您相同的问题,然后我检查了kurourin GitHub存储库,发现了另一个基于订阅的分页。单击此链接-上面的链接将帮助您我遇到了与您相同的问题,然后我检查了kurourin GitHub存储库,发现了另一个基于订阅的分页。单击此链接-以上链接将帮助您
'click .studentprevious': function () {
if (Session.get('skip') > 0 ) {
Session.set('skip', Session.get('skip') - 2 );
}
},
'click .studentnext': function () {
Session.set('skip', Session.get('skip') + 2 );
}