これには、前の質問「 IndexedDB Fuzzy Search 」のサンプル コードが含まれています。カーソルの結果を入力ボックスにバインドしてオートコンプリート効果を作成し、結果が選択されたときに objectStore からの異なる値をフォームの複数の入力ボックスに入力するにはどうすればよいですか? ライブラリなしでこれを行いたいと思います。
HTML 入力ボックス。
<input name="name" id="name"> //search by name, when a name is selected the last name and age are automatically attached to the other input boxes
<input name="lastname" id="lastname">
<input name="age" id="age">
ジャバスクリプト。
var result = [];
db.transaction(['table'], IDBTransaction.READ_ONLY)
.objectStore('table')
.openCursor(
IDBKeyRange.bound(searchTerm, searchTerm + '\uffff'),
IDBCursor.PREV)
.onsuccess = function (e) {
e || (e = event);
var cursor = e.target.result;
if (cursor) {
result.push([cursor.value.column1, cursor.value.sortcolumn]);
cursor.continue();
} else {
if (result.length) {
result.sort(function (a, b) {
return a[1] - b[2];
});
}
// Process code here
}
};