问题描述
- indexeddb复合查询问题
-
问题描述:indexeddb用index筛选条件,我在index上添加了两个字段,如下代码:
var userStore = db.createObjectStore("users",{keyPath:"id",autoIncrement: true}); userStore.createIndex("index_name", ["name","age"], { unique: false }); userStore.put({name: "a",age:0}); userStore.put({name: "be",age:2}); userStore.put({name: "b",age:5}); userStore.put({name: "c",age:3}); userStore.put({name: "d",age:7}); userStore.put({name: "e",age:6}); userStore.put({name: "dfgf",age:9});
我根据name和age做为条件查询,如下代码:
var store = localDatabase.db.transaction("users","readonly").objectStore("users"); var lowerBound = [name,1]; var upperBound = [name+"uffff",5]; var range = IDBKeyRange.bound(lowerBound,upperBound); var request = store.index("index_name").openCursor(range); request.onsuccess = function(event) { var cursor = event.target.result; if (cursor) { var users = cursor.value; showData(users.id, users.name); cursor.continue(); } };
最终效果:
age大于5的数据不应该显示出来,age的条件没有用到,求解
时间: 2024-10-25 19:37:23