Indexed Db中的两个索引列在Firefox中不起作用

时间:2013-09-25 09:30:01

标签: firefox indexeddb

我正在为我的应用程序使用Indexed Db

我有一个表产品,我添加了两个索引

 var product = evt.currentTarget.result.createObjectStore("product", { keyPath: product_id" });
 product.createIndex("productIndex", "product_id", { unique: true });
 product.createIndex("barCodeIndex", "ean_product", { unique: false });

在我的代码中,首先我搜索产品ID,如果结果为null,我就是 搜索条形码。问题是我写的代码正在运行 在Chrome和IE 10中很好,但在FF中不起作用。请建议。

在我正在搜索条形码的其他部分,该行 “var keyBarcode = barcodeSearch.index(”barCodeIndex“);”抛出异常 “操作失败,因为找不到请求的数据库对象。例如,对象存储不存在但正在打开。”

   var searchKey = IDBKeyRange.only(productId);
    var productSearch = localDatabase.db.transaction("product").objectStore("product");
    var key = productSearch.index("productIndex");
  key.get(searchKey).onsuccess = function (evt) {
        var productSearchResult = evt.target.result;
        if (productSearchResult != null) {
         //some logic

        } else {
            //search on bar code
            var barcode = $("#txtProductCode").val().trim();
            var barcodeKey = IDBKeyRange.only(barcode);
            var barcodeSearch = localDatabase.db.transaction("product").objectStore("product");

                var keyBarcode = barcodeSearch.index("barCodeIndex");
                keyBarcode.get(barcodeKey).onsuccess = function(event) {
                    var barcodeSearchResult = event.target.result;

                    if (barcodeSearchResult != null) {
                        //some logic                     
                    } 

                };

        }

    };

1 个答案:

答案 0 :(得分:0)

我自己解决了这个问题。

套管存在问题。在表上创建的索引是“BarCodeIndex”,我试图使用“barCodeIndex”。

Point to be noted : Index names are case sensitive
相关问题