嗯,這是我想通了
Template.portfolioView.helpers({
project: function() {
return Projects.findOne({_id: Router.current().params._id});
},
nextproject: function() {
if(this.project) {
var x = Projects.find({ timestamp : { $gt : this.project.timestamp }}, {limit: 1, sort : { timestamp: 1}}).fetch();
if(x.length < 1) {
var y = Projects.find({ }, {limit: 1, sort : { timestamp: 1}}).fetch();
}
return x.length > 0 ? x[0]._id : y[0]._id;
}
},
prevproject: function() {
if(this.project) {
var x = Projects.find({ timestamp : { $lt : this.project.timestamp }}, {limit: 1, sort : { timestamp: -1}}).fetch();
if(x.length < 1) {
var y = Projects.find({ }, {limit: 1, sort : { timestamp: -1}}).fetch();
}
return x.length > 0 ? x[0]._id : y[0]._id;
}
}
});
在路線我必須找到將項目作爲數據變量
this.route('portfolioView', {
path: '/portfolio/view/:_id',
waitOn: function() {
return Meteor.subscribe('projects', this.params._id);
},
data: function(){
return {project: Projects.findOne({_id: this.params._id})};
},
onAfterAction: function() {
if (!Meteor.isClient) {
return;
}
var project = this.data().project;
SEO.set({
title: 'Revolt Visual | '+ project.name,
meta: {
'description': project.description
}
});
}
});