我创建了一个自动完成组件,其中数据源是 localhost solr。一切正常,但我需要以下拉菜单框的格式提供建议,但在我的情况下,它显示为普通列表,没有下拉菜单出现。
这是我的代码,
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@ taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Autocomplete</title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="jquery.ui.core.js"></script>
<script type="text/javascript" src="jquery.ui.position.js"></script>
<script type="text/javascript" src="jquery.ui.widget.js"></script>
<script type="text/javascript" src="jquery.ui.autocomplete.js"></script>
<SCRIPT type="text/javascript">
$(function() {
$("#autotextsearch").autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://localhost:8080/solr2/select?q=Query%3A"+request.term+"*&wt=json",
data: {
style: "full",
maxRows: 5
},
dataType: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
cache:false,
asynch:false,
success: function( data ) {
data=parse();
function parse(){
var parsedQueries=[];
for(var i=0;i<data.response.docs.length;i++){
parsedQueries[i]=data.response.docs[i].Query;
}
return parsedQueries;
}
response($.map(data, function( item ) {
return {
label: item,
value: item
};
}));
}
});
},
minLength: 2
});
});
</SCRIPT>
</head>
<body>
<f:view>
<label for="autotextsearch">Search Here : </label>
<input id="autotextsearch"/>
</f:view>
</body>
</html>