我正在尝试使用语义用户界面构建自动完成搜索,但我不知道如何显示我的数据......
<script type="text/javascript">
$(document).ready(function () {
$('.ui.search').search({
apiSettings: {
url: '/autocomplete/{query}',
minCharacters : 3,
},
});
});
</script>
CONTROLLER
public function autocomplete($query)
{
$search = "%$query%";
$data = Tag::where("name","LIKE",$search)->get();
return response()->json($data);
}
JSON DATA
"id":3,"name":"Argentina","description":"Argentina","status":"1","created_at":"2016-07-11 02:36:37","updated_at":"2016-07-11 02:36:37"},{"id":4,"name":"Argelia","description":"argelia","status":"1","created_at":"2016-07-11 02:36:48","updated_at":"2016-07-11 02:36:48"}]
答案 0 :(得分:1)
基于他们的文档,我相信你正在寻找这样的东西(注意,我从未使用过这个库 - 并且没有测试过)。查看onResponse
方法:
<script type="text/javascript">
$(document).ready(function () {
$('.ui.search').search({
apiSettings: {
url: '/autocomplete/{query}',
minCharacters : 3,
onResponse: function(results) {
var response = {
results : []
};
$.each(results, function(index, item) {
response.results.push({
title : item.name,
description : item.description
//url : item.html_url
});
});
return response;
},
},
});
});
</script>