相关疑难解决方法(0)

IndexedDB模糊搜索

好的,首先,对不起我的英语.

我在一个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
  });
});
Run Code Online (Sandbox Code Playgroud)

我想用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();
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

但是速度太慢而且我的代码有问题......我想知道有没有更好的方法来做到这一点.

谢谢回复.

javascript indexeddb

22
推荐指数
1
解决办法
7343
查看次数

标签 统计

indexeddb ×1

javascript ×1