2016-12-20 32 views
2

我有一個字符串字段稱爲行業,人們將進入他們的行業。例如農業,製造業,信息技術,園林綠化等。顯示結果的清單減去重複液體

我想用液體輸出這些數據,但是我想將它放到下拉菜單中的Web App Search表單中,以便用戶可以搜索特定的字段。因此我不想添加任何重複的項目。

E.g.來自用戶的條目包括:農業,製造業,農業,IT,園林綠化,農業 - 您可以看到農業被使用了3次。如果我用它下面將列出3次:

<select> 
{module_webapps id="12345" collection="industry" filter="all" template=""} 
{% for item in industry.items %} 
    <option value="{{item.industry}}">{{item.industry}}</option> 
{% endfor %} 
</select> 

我如何使用循環或數組只顯示一次產業和隱藏所有其他副本?

感謝

回答

0

您可以capture所有項目的字符串。然後使用字符串過濾器split將其轉換爲基於分隔符的數組。然後使用uniq陣列過濾器刪除所有重複項。最後,迭代結果數組以構建您的下拉菜單。

<select> 
{module_webapps id="12345" collection="industry" filter="all" template=""} 

{% capture items %} 
{% for item in industry.items %} 
{{item.industry}}, 
{% endfor %} 
{% endcapture %} 

{% for item in items | split: ',' | uniq %} 
    <option value="{{item}}">{{item}}</option> 
{% endfor %} 
</select> 
+0

我不認爲uniq在商業催化劑中起作用。 – Daut