Meteor リーダーボードに基づいた Meteor 投票プロジェクトをほぼ終了しましたが、少し問題があります。
私のDBの各アイテムには、投票で指定されたポイントを持つ配列があります。配列を合計し、結果をアプリに表示します。問題: ソートされていません。名前 (name = _id) でソートされているだけです。
HTML:
<template name="voting">
{{#each books}}
{{> book}}
{{/each}}
</template>
<template name="book">
<div class="book {{selected}}">
<span class="name">{{_id}}</span>
<span class="totalscore">{{totalscore}}</span>
</div>
</template>
JS
Template.voting.books = function () {
return Books.find({flag: "score20130901"}, {sort: {totalscore: -1, _id: 1}});
};
Template.book.totalscore = function () {
var total = 0;
for (var i=0; i<6; i++) {
total += this.score20130901[i];
}
return total;
};
DB(文書の例)
{
_id: "Dancing Joe",
flag: "score20130901",
score20130714: [0,0,8,0,0],
score20130901: [0,4,0,5,0]
}