树枝排序在这种情况下不起作用

时间:2017-08-26 00:51:37

标签: twig

排序在这里不起作用

{% for key, season in seasons | sort %}

但是在这里

{% for episode in season | sort %}

这是整个twig片段

{% for key, season in seasons | sort %}  {# <<this is the sort not working #}
    <button class="accordion"><h5>Season {{ key }}</h5></button>
    <div class="panel">
    {% for episode in season | sort %}
        <li><h5><b>{{ episode.title }}</b></h5></li>
    {% endfor %}
    </div>
{% endfor %}

1 个答案:

答案 0 :(得分:0)

如果您需要反向排序,请使用它。

{% for key, season in seasons |sort((a, b) => a.id <= b.id) %} 
  {% for episode in season | sort %}
    {{ episode.title }}
  {% endfor %}
{% endfor %} 

您只需要添加此代码。

|sort((a, b) => a.id <= b.id)