「都市」入力フィールドで jQuery オートコンプリート インスタンス (v1.1) をデバッグしています。
オートコンプリート データ バインディングはkeyup
、フィールド値の長さが少なくとも 2 で、値が変更された場合にのみ、フィールドのイベントで設定されます。
データ バインディング、ヒント リスト、およびオートコンプリートは正常に機能しています。しかし、何かが間違っています。ログを見ると、サーバーに投稿された都市の入力値の 3 番目と 4 番目の文字が欠落していることが何度もあります。いくつかの例:
"trpani" instead of "trapani"
"fienze" instead of "firenze"
"scndicci" instead of "scandicci"
"brdisi" instead of "brindisi"
"paermo" instead of "palermo"
"caliari" instead of "cagliari"
バグを再現することはできませんが、偶然ではないと確信しています! エラーは 3 文字目で発生します。挿入時に、Javascript の処理がキーボード バッファと衝突するようです。
だから、私は推測しますが、よくわかりませf i r e n z e
ん.r
fienze
質問
何が起こっている?エラーを再現できないのはなぜですか? なにが問題ですか?
オートコンプリートを設定するために使用されるコードは次のとおりです。
/*
* here I store the previous value
*/
var storeCity;
$('#City').keydown(function(){
var val = $(this).val();
storeCity = (val.length >=2 ? val.substring(0,2):"");
});
/*
* the autocomplete is set only if
* - the City value has changed compared to the storeCity value
* - the City value has lenght at least 2
* - remark: using the keypress does not solve the issue
*/
$('#City').keyup(function(){
var val = $(this).val();
if(val.length>=2 && val.substring(0,2)!=storeCity){
getLocations('#City');
}
});
function getLocations(cityId){
var hint = $(cityId).val().substring(0,2);
$.ajax({
type: "GET",
url: "/include/getLocations.asp",
data: ({location : hint}),
async: false,
error: function() {},
success: function(dataget) {
var result = dataget.split("\n");
$(cityId).flushCache();
$(cityId).autocomplete(result, {
pleft: 100px,
minChars: 2,
matchContains: true,
max: 3000,
delay: 100,
formatItem: function(row){...},
formatMatch: function(row){ return row[0]; },
formatResult: function(row){ return row[0]; }
});
$(cityId).result(function(event,data){...});
}
});
}