Autocomplete 下拉選項過多影響體驗。兩種限制方案:
.ui-autocomplete {
max-height: 200px;
overflow-y: auto;
overflow-x: hidden;
}
// 後端
@GetMapping("/suggest")
public List suggest(@RequestParam String term, @RequestParam(defaultValue="10") int limit) {
return repo.findTopByNameStartingWith(term, PageRequest.of(0, limit));
}
// 前端
$('#input').autocomplete({
source: function(request, response) {
$.getJSON('/suggest', {term: request.term, limit: 10}, response);
}
});
靜態字典/標籤 → 客戶端 CSS;動態業務數據/用戶搜索 → 服務端分頁。