- 我最近刚开始使用 Laravel 5.5。我卡在了排序功能上。
- 我在 View 中使用了 onchange 函数,因此用户可以选择按升序/降序排序。
- 关键是我如何在用户按名称搜索或按类别排序后按产品价格排序?
- 我进行了搜索,但不明白如何在 Laravel 中通过 URL 发送参数。如何将其发布到路线/网址上?我怎样才能把它用在 Controller 中?
查看:
<select id = "sorting" name = "sorting" class="form-control selecting" onchange="Sorting()">
<option value="normal">Sort by Price</option>
<option value="asc">Price Ascending</option>
<option value="desc">Price Descending</option>
</select>
Javascript:
function Sorting() {
var sorting = document.getElementById('sorting').value;
if(sorting == "asc")
{
window.location.href="{{route('product-management.asc')}}";
}
if(sorting == "desc")
{
window.location.href="{{route('product-management.desc')}}";
}
}
最佳答案
使用 HTML 表单将数据发布到某个 URL,请参阅 https://www.w3schools.com/html/html_forms.asp .
如果您不想使用 HTML 表单,您可以使用 AJAX 请求。参见 https://www.w3schools.com/xml/ajax_intro.asp
顺便说一句,我建议您在客户端使用排序,这样不那么复杂并且不会使用不必要的资源。
关于javascript - Laravel 5.5 中的多字段排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46907129/