首先,对于我的英语表示抱歉。
我正在开发一个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();
}
}
};
但是这个方法太慢了,而且我的代码有漏洞... 我想知道是否有更好的方法。
谢谢回复。
\uffff
作为您的标记,而不是z。如果您使用z,当搜索“wiki”时,您将无法获得“wikipædia”这样的搜索结果... - odinho - Velmont