流星按分数创建用户排名

问题描述 投票:0回答:1

我是一个初学者。我正在将Meteor用于学校项目,并尝试创建排名。我想根据用户的得分对其进行排名。我想显示他们的用户名和分数。

enter image description here

我发现用于对用户和以下项进行排序的功能

Meteor.users.find({}, { sort: { score: -1 } });

我想在下面的代码中包括它

Template.classement.helpers({

  users() {
    Meteor.users.find().forEach(function(oneUser) {
      const affichage = `nom : ${oneUser.username} score : ${oneUser.profile.score}`;
      console.log(affichage);
      console.log(oneUser.profile.score);
      console.log(oneUser);
    });

    return Meteor.users.find();
  },


});

在html端,我有这个要显示,但是没用

<template name="classement">
  <h1>Classement</h1>
 {{#each users}}
    {{user}}
  {{/each}} 
</template>

您能帮我吗。 (对不起,英语不是我的母语)。

meteor username ranking
1个回答
0
投票

欢迎您使用SO!

问题在排序中:

Meteor.users.find({}, { sort: { score: -1 } });

这将尝试按顶级字段score对文档进行排序。当score存储在子文档中的配置文件下。

在MongoDB中按子模块的属性排序的语法是:

Meteor.users.find({}, { sort: { 'profile.score': -1 } });
© www.soinside.com 2019 - 2024. All rights reserved.