好的,首先,对不起我的英语。
我正在一个 Web 项目中工作,当我在输入框中输入内容时会显示建议,但我想使用 IndexedDB 来提高 Firefox 中的查询速度。
使用 WebSQL 我有这句话:
db.transaction(function (tx) {
var SQL = 'SELECT "column1",
"column2"
FROM "table"
WHERE "column1" LIKE ?
ORDER BY "sortcolumn" DESC
LIMIT 6';
tx.executeSql(SQL, [searchTerm + '%'], function(tx, rs) {
// Process code here
});
});
我想用 IndexedDB 做同样的事情,我有这个代码:
db.transaction(['table'], 'readonly')
.objectStore('table')
.index('sortcolumn')
.openCursor(null, 'prev')
.onsuccess = function (e) {
e || (e = event);
var cursor = e.target.result;
if (cursor) {
if (cursor.value.column1.substr(0, searchTerm.length) == searchTerm) {
// Process code here
} else {
cursor.continue();
}
}
};
但是太慢了,我的代码有问题。我想知道有没有更好的方法来做到这一点。
谢谢回复。