我需要在jekyll中按排名订购商品

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

所以我有一张桌子上有一个机器人比赛的分数。

我的google.yml:

teams:
  - rank: 1 
    number: 7854
    name: Midnight Madness 
    qp: 10
    rp: 437
    plays: 5

  - rank: 2 
    number: 7641
    name: MSET Beta Fish
    qp: 10
    rp: 412 
    plays: 5

  - rank: 3 
    number: 12804
    name: LED
    qp: 10
    rp: 302 
    plays: 5

https://ibb.co/dtc776

代码是:

---
layout: pastTournaments
title: Google Tournament
permalink: /tournaments/google/
---

<h5 class="column-wrapper centered">These are the rankings for the Google Qualifying tournament, which was hosted on December 2, 2017.</h5>
<br>
<div class="column-wrapper">
    <div class="grid-x">
        <div class="large-6 shrink cell">
            <table>
                <thead>
                    <tr>
                    <th width="20" class="centered">Rank</th>
                    <th width="150" class="centered">Team Number</th>
                    <th width="150" class="centered">Team</th>
                    <th width="50" class="centered">QP</th>
                    <th width="50" class="centered">RP</th>
                    <th width="50" class="centered">Plays</th>
                    </tr>
                </thead>
                <tbody>
<!--This is where the jekyll starts-->
                    {% assign order = 0 %}
                    {% for team in site.data.google.teams %}
                        {% assign order = order | plus: 1 %}
                        {% if team.rank == order %}
                            <tr>
                                <td class="centered">{{ team.rank }}</td>
                                <td class="centered">{{ team.number }}</td>
                                <td class="centered">{{ team.name }}</td>
                                <td class="centered">{{ team.qp }}</td>
                                <td class="centered">{{ team.rp }}</td>
                                <td class="centered">{{ team.plays }}</td>
                            </tr>
                        {% endif %}
                    {% endfor%}
                </tbody>
            </table>
        </div>
</div>

当我改变我的.yml文件的等级时,我需要它,所以它堆叠,就像我用1和2交换1和1.这两个就像这样消失:https://ibb.co/kq0ifR

当我更改.yml文件中的排名时,如何进行重新排序?

注意:我确实有一些其他不重要的zurb东西,这就是为什么列没有关闭

html zurb-foundation jekyll liquid
1个回答
1
投票

您可以使用sort液体过滤器。

{% assign sorted = site.data.google.teams | sort:"rank" %}

然后:{% for team in sorted %} ......

© www.soinside.com 2019 - 2024. All rights reserved.