jqueryのオートコンプリートをいじっていました。最小長を 3 に設定しました。
「sci」と入力すると、タイトルに「sci」が含まれるすべてのレコードが取得されます。文字「sci」を含むすべてのレコードが返されて表示されるため、この部分は正しく機能しています。
しかし、入力を続けると (もちろん一時停止した後です。この時点で「scisdfgdsfsd」と入力しました)、以前の選択肢が表示されます。「scisdfgdsfsd」という文字をタイトルに使用したレコードは確かにありません。
これを修正する方法についてのアイデアはありますか? ありがとう!:)
アクション中の「エラー」のスクリーンショット
作業: http://awesomescreenshot.com/0a2wuo2aa
動作しない: http://awesomescreenshot.com/023wuo507
私のjqueryコード
$(function() {
$("#course").autocomplete({
minLength: 3,
source: function( request, response ) {
$("#commentsSection").hide();
$("#instanceIdSection").hide();
$.getJSON("/issu/GetCourses.html", {term: request.term}, function(data, status) {
if (data.length > 0) {
response(data);
} else {
getEventComments();
getEventSessions();
}
});
},
select: function (event, ui) {
alert("select");
getEventComments();
getEventSessions();
},
change: function (event, ui) {
alert("change");
getEventComments();
getEventSessions();
}
});
function getEventSessions(){
$.getJSON("/issu/GetEventSessions.html",{description: $("#course").val()}, function(data, status){
if (data.length != 0) {
$("#instanceId").empty();
$.each(data, function () {
$("#instanceId").append($('<option></option>').attr("value", $(this)[0]).text($(this)[1]));
});
$("#instanceIdSection").show();
}
});
}
function getEventComments() {
$.get("/issu/GetEventComments.html",{description: $("#course").val()}, function(data, status){
if (data.length != 0) {
$("#comments").text(data);
$("#commentsSection").show();
}
});
}
});