0
我想在我的表單上有一個自動完成輸入,我有問題獲取數據顯示。有很多關於此的帖子,但看起來像許多不同的方式。我一直試圖按照jQuery網站上的例子,但我想我只是沒有得到正確的返回數據?我的頁面看起來像:jquery自動完成JSON
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#Codes").autocomplete({
source: function(request, response) {
$.ajax({
url: "/jreqlib",
dataType: "json",
data: {
featureClass: "P",
style: "full",
maxRows: 25,
},
success: function(data) {
response($.map(data, function(item) {
return {
label: item.name,
value: item.name
}
}));
}
});
},
minLength: 1,
open: function() {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function() {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
});
</script>
</head>
<body>
<form>
<input id="Codes">
</form>
</body>
</html>
我是從服務器返回什麼看起來是這樣的:
[{"1234":"1234"},{"134":"134},{"567":"567"}]
我喜歡當我在框中單擊是,它讓我看到「1234」和「567」,如果我輸入1,則會出現「1234」和「134」,如果我輸入12,那麼只會出現「1234」等。
任何幫助,將不勝感激 TIA
我沒有使用jQuery的從自動完成它看起來像你正在嘗試使用項目之前。名稱,但您的json不包含名稱。 – BlueBird 2013-02-22 18:59:17
我試過改變json,所以它是[{「name」:「1234」},{「name」:「134}等,但仍然沒有去:( – Analog 2013-02-22 22:32:18