我从四种不同的出版物(具有不同的结构)中过滤了结果。
Router.route('/anything/:_id', {
name: 'anything',
data: function () {
return {
result1: Collection1.find({'article.reference': this.params._id}),
result2: Collection2.find({'edition.section.reference': this.params._id}),
result3: Collection3.find({'reference': this.params._id}),
result4: Collection4.find({'anything.reference': this.params._id})
};
}
});
现在我只是这样显示它们:
<h4>Result 1</h4>
{{#each result1}}
{{#each article}}
{{author}}. {{title}}. {{../journal}} ({{year}}):{{edition}}; S.{{pageNumbers}}
{{/each}}
{{/each}}
[...]
<h4>Result 4</h4>
{{#each result4}}
{{#each edition}}
{{#each section}}
{{../../author}}. {{../../book}} ({{../year}}). {{../edition}}. {{../../publisher}}. S.{{pageNumbers}}
{{/each}}
{{/each}}
{{/each}}
我对路由器数据中给出的每个结果执行此操作。所以我得到了四个排序列表。
但我只需要一个大列表,其中的所有元素都按一般顺序排序。因此,我想首先为每个结果构建字符串(现在这是在模板中完成的)(每个集合将被不同地处理,因为结果字符串不同),然后对结果数组进行排序以将其推送到模板中。
所以模板就是:
<h4>Result</h4>
{{#each result}}
<p>{{line}}</p>
{{/each}}
最佳答案
这难道不是一个选择吗?
var cursor = Collection.find();
cursor.forEach(function(doc){
console.log(doc._id);
// fill new object here...
});
关于javascript - Meteor:使用四个结果中的字符串构建一个新对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32631962/