您無法將Array
傳遞給where
過濾器。它不會嘗試通過循環遍歷所有哈希像{"title"=>"bar1"}
來找到所需的值,它只會根據傳遞的字符串評估屬性。所以,那些Hash
將永遠不會等於bar1
。
我的兩分錢:
簡化people.yml通過刪除activities.name
鍵: 注:兩個activities
陣列演講是等價的。
- name: Foo
activities: [ bar1, bar2 ]
- name: Bar
activities:
- bar3
- bar4
您現在可以使用contains
過濾檢索已BAR1作爲活動的人。 contains
filters strings
or array
like ["bar1", "bar2"]
{% assign selected = "" | split: "/" %} --> create empty array
{% for people in site.data.people %}
{% if people.activities contains 'bar1' %}
--> add people to array if match is found
{% assign selected = selected | push: people %}
{% endif %}
{% endfor %}