【发布时间】:2019-09-19 04:17:18
【问题描述】:
我将可排序链接布局更改为选择下拉菜单。但是我不知道如何选择选择的选项。
到目前为止,这是我的代码。 我把 sortable.link htwl twig 改成了这个
<option{% for attr, value in options %} {% if attr == 'href' %}value="{{ value }}" {% else %}{{ attr }}="{{ value }}"{% endif %}{% endfor %} >{{ title }}</option>
我的树枝文件看起来像这样:
<select onChange="window.location=this.value;">
{{ knp_pagination_sortable(properties, 'Title A-Z', 'a.title', {}, {'direction': 'asc'}) }}
{{ knp_pagination_sortable(properties, 'Title Z-A', 'a.title', {}, {'direction': 'desc'}) }}
</select>
onchange 下拉菜单有效,但在再次加载时不显示所选选项。请指教 :) 也许这也不是设置选择下拉列表的最佳方式。非常感谢我的代码的任何改进
编辑
我查看了其他模板示例,发现您可以获取方向和顺序,但它不能完全使用 asc/desc 它出错。 这是我更新的选项代码。
<option{% for attr, value in options %} {% if attr == 'href' %}value="{{ value }}" {% else %}{{ attr }}="{{ value }}"{% endif %}{% endfor %} {% if app.request.get('direction') == 'desc' and app.request.get('sort') == key %} selected="selected" {% elseif app.request.get('direction') == 'asc' and app.request.get('sort') == key %} selected="selected"{% else%} no{% endif %}>{{ title }}</option>
然后我在树枝上更新了选择
<select onChange="window.location=this.value;">
{{ knp_pagination_sortable(properties, 'Title A-Z', 'a.title', {}, {'direction': 'asc'}) }}
{{ knp_pagination_sortable(properties, 'Title Z-A', 'a.title', {}, {'direction': 'desc'}) }}
{{ knp_pagination_sortable(properties, 'price (low to high)', 'a.price', {}, {'direction': 'asc'}) }}
{{ knp_pagination_sortable(properties, 'Price (high to low)', 'a.price', {}, {'direction': 'desc'}) }}
</select>
感谢您的帮助。谢谢
【问题讨论】:
标签: symfony select dropdown knppaginator