我试着简单地把物体算进一个城市
在巴黎,我有 5 个对象,我不想显示 11111 但只有 5 个,
我的代码
{% set newAnnounceCity = [] %}
{% for item in announceCity %}
{% if item.infoCity is not null %}
{% if item.infoCity.city not in newAnnounceCity %}
<span class=" font-semibold mr-2 text-left flex-auto">
<a href="{{path('app_city_show',{slug: item.infoCity.slug})}}">
<button class=" m-2 p-2 pl-5 pr-5 bg-transparent border-2 border-red-500 text-red-500 text-lg rounded-lg hover:bg-gradient-to-b hover:from-red-600 hover:to-pink-500 hover:text-gray-100 focus:border-4 focus:border-red-300">
{{ (item.infoCity.city) }}
{% for key in item.infoCity.announce|keys %}
{{key|length }}
{% endfor %}
{% set newAnnounceCity = newAnnounceCity|merge([item.infoCity.city]) %}
</button>
</a>
</span>
{% endif %}
{% else %}
{% endif %}
{% endfor %}
有人可以帮助我
我试着数一个键对象
如果没有输入数组的样本结构,很难猜测,但也许可以尝试替换
{% for key in item.infoCity.announce|keys %}
{{key|length }}
{% endfor %}
简单地
{{ item.infoCity.announce|length }}