【问题标题】:Meteor create user ranking by score [closed]流星按分数创建用户排名[关闭]
【发布时间】:2020-05-26 05:24:36
【问题描述】:

我完全是初学者。我正在将 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 ranking


    【解决方案1】:

    欢迎来到 SO!

    问题在于排序:

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

    这会尝试按顶级字段score 对文档进行排序。虽然您将 score 存储在子文档中,但在配置文件下。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-15
      • 2018-12-06
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 2016-11-10
      相关资源
      最近更新 更多