我在laravel上安装了elasticquent包。搜索操作运行顺畅。但是我需要创建一个基于数据类型URL的类别。
弹性包:https://github.com/mustafaaloko/elasticquent5
我的搜索控制器方法:
public function search(Request $request){
$key = $request->input('phrase');
$companies = $this->company->search($key);
$projects = $this->project->search($key);
return \Response::json([
'companies' => $companies,
'projects' => $projects
]);
}Easyautocomplete Javascript代码:
$(document).ready(function() {
var options = {
url: function(phrase) {
return "{{ url('webapps/search') }}";
},
categories: [{
listLocation: "projects",
maxNumberOfElements: 5,
header: "Projects"
}, {
listLocation: "companies",
maxNumberOfElements: 5,
header: "Companies"
}],
getValue: function(element) {
return element.name;
},
ajaxSettings: {
dataType: "json",
method: "GET",
data: {
dataType: "json"
}
},
preparePostData: function(data) {
data.phrase = $(".search-input").val();
return data;
},
requestDelay: 400,
theme: "square"
};
$(".search-input").easyAutocomplete(options);
});我的搜索结果(示例)
如何创建类别链接
公司url:http://localhost/companies/{id}项目url:http://localhost/projects/{id}
谢谢。
发布于 2016-09-07 16:18:55
为您的结果创建自定义模板:
template: {
type: "custom",
method: function(value, item) {
return "<a href='{{url('companies')}}/" + item.id+ "' >" + item.name+ " </a> "
}https://stackoverflow.com/questions/39364528
复制相似问题