【发布时间】:2011-10-28 12:12:06
【问题描述】:
好的,首先,对不起我的英语。
我正在从事一个网络项目,当我在输入框中输入内容时会显示提示,但我想使用 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();
}
}
};
但是太慢了,而且我的代码有问题。我想知道有没有更好的方法来做到这一点。
感谢回复。
【问题讨论】:
标签: javascript indexeddb