所以,我正在做一个 Meteor 项目,我无法让这条路线正确生成,或者根本无法生成。
<template name="browseAll">
<h3>List of classes with books available!</h3>
<ul>
{{#each aggCount}}
<li><a href="{{ pathFor 'browse-class' }}">{{ _id }}</a> ({{ count }})</li>
{{/each}}
</ul>
</template>
正在迭代的数据是使用 MongoInternals 聚合的结果,如下所示:
(服务器/methods.js 摘录):
classCount: function() {
// Attempt aggregation of the books table to count by class, maybe.
var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
var col = db.collection("books");
var aggregateSync = Meteor._wrapAsync(col.aggregate.bind(col));
var pipeline = [
{$group: {_id: "$class", count: {$sum: 1}}},
{$sort: {_id: 1}}
];
var theAnswer = aggregateSync(pipeline);
return theAnswer;
}
似乎数据通过正常,来自聚合的样本数据(进入模板)如下所示:
[ { _id: 'ADNR1234', count: 2 }, { _id: 'ARTH1234', count: 1 } ]
那是我得到的模板代码,这是它应该使用的路线:
this.route('browse-class', {
path: '/browse/:_class',
data: function() {
var booksCursor = Books.find({"class": this.params._class},{sort:{"createdAt": 1}});
return {
theClass: this.params._class,
numBooks: booksCursor.count(),
books: booksCursor
};
}
});
我不明白。数据正在显示,我想做的是为browse-class
(路由)生成一个 URL,该 URL{{ _id }}
将助手中的值作为参数,以便生成如下内容:
application.org/browse/CLSS