该操作返回一个 JSonResult 并且内容是正确的。我错过了自动完成代码中的某些内容?
HTML:
<input type="text" class="span12" id="mytextbox" />
的JavaScript:
<script>
$(document).ready(function () {
$("#mytextbox").autocomplete({
minLength: 2,
source: function(request,response) {
$.ajax({
url: "MyController/MyAction",
type: "POST",
dataType: "json",
data: { term: request.term },
success: function (data) {
response($.map(data, function (item) {
return { firstname: item.FirstName, lastname: item.LastName, code: item.Code };
}))
}
})
},
messages: {
noResults: "", results: ""
}
})
.data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li>")
.append("<a>" + item.firstname + "<br>" + item.lastname + "</a>")
.appendTo(ul);
};
})
</script>