【发布时间】:2016-06-11 07:31:57
【问题描述】:
我正在使用DexieJS 从 IndexedDB 中获取数据。我已经使用 v. 1.1.0 和 1.2.0 完成了以下测试。
它非常适合简单查询,但不幸的是我无法链接多个 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();
【问题讨论】:
标签: javascript where-clause indexeddb dexie