1
我正在使用DexieJS從IndexedDB中獲取數據。我已經用1.1.0和1.2.0版做了以下測試。DexieJS(indexedDB)鏈多個.where子句
它適用於簡單的查詢,但不幸的是我無法鏈接多個where子句。
首先,我已經試過這
var collection = db[table];
collection = collection.where('Field').equals("1");
return collection.count();
,那就是工作。 然後,我需要添加一個WHERE子句,但只有在一個給定的值設置:
var collection = db[table];
collection = collection.where('Field').equals("1");
if(value) collection = collection.where('Field2').above(value);
return collection.count();
這一次失敗。出於測試目的,我也嘗試過:
var collection = db[table];
collection = collection.where('Field').equals("1")
.and('Field2').above(value);
return collection.count();
var collection = db[table];
collection = collection.where('Field').equals("1")
.and().where('Field2').above(value);
return collection.count();
var collection = db[table];
collection = collection.where('Field').equals("1")
.where('Field2').above(value);
return collection.count();
這些都沒有工作。我開始認爲這根本不可能,但由於方法and()
存在,所以必須有辦法!
PS工作的:
var collection = db[table];
collection = collection.where('Field2').above(value);
return collection.count();
對不起,我忘了說我也試過這個'collection = collection.where('Field')。equals(「1」)。和('Field2')。(上面的值);' – ghego1
什麼都沒有,我得到一個白色的屏幕,甚至添加'.catch(function(err){console.log(err);});'。我必須說,我正在使用ngDexie進行角度測試,或許這是與 – ghego1
@ ghego1奇怪的錯誤。我現在會刪除這個答案,一旦我有時間建立一個測試用例就回來。 –