2013-09-25 17 views
0

不工作我使用索引分貝我的應用程序兩個指標列在Firefox

我有,我已經添加了兩個指標

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,如果結果爲空,我在條碼上搜索 。問題是我寫的代碼在Chrome和IE 10中正常工作 ,但不能在FF中工作。請建議。

在我搜索條形碼的else部分,行 「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      
        } 

       }; 

     } 

    }; 
+0

你能發佈可運行代碼嗎? –

回答

0

我自己解決了這個問題。

套管問題。在表上創建的索引是「BarCodeIndex」,我試圖使用「barCodeIndex」。

Point to be noted : Index names are case sensitive