私はこれをしばらく取り組んでおり、どこにも出てこないようです。基本的に私はクラスによって入力の束にオートコンプリートを持っていますが、私はajaxを投稿するオブジェクトを構築するために特定の入力IDを取得する必要があります(GETではなくこのプロジェクトでPOSTを使用する必要があります)。クラスのjQuery自動補完、IDの取得方法
$(".input_autocomplete").autocomplete({
source: function(request, response) {
// here is where I get the hash from local storage,
// reference the id and build the object
// tried this.id, $(this).prop('id'), no luck
$.ajax({
url: '/somepath/filename.htm',
contentType: 'application/json',
dataType: 'json',
type: 'POST',
data: JSON.stringify(obj),
success: function(json) {
return {
label: item.label,
value: item.label
}
},
error: function() {
// error handling
}
}); // ajax
} // source
});
私はjQueryのに非常に新しいんだけど、あなたはATTRを使用してみましたが( 'id')の代わりに '.prop'( 'id')の代わりに?私の知る限り、idは小道具ではなくattrです。また、ドットシンタックスを使用しているので、jQueryオブジェクトをターゲットにしているので、$(this)を使うべきです。それが問題を解決することを願っています。 – rafaelbiten