You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Dexie.js筛选仅返回单个值问题排查求助

DexieDB查询仅返回第一条数据的问题分析

你的DexieDB结构

const db = new Dexie('shipment-execution');
db.version(1).stores({
    root: '++id,shipmentid,stopid',
})

数据库存储的数据

idshipmentidstopid
1600000110
2600000120
3600000130
4600000210
5600000220

你的查询代码

db.root.where({shipmentid : '6000001'}).toArray().then((d)=>{
    console.log(d);
})

实际输出结果

idshipmentidstopid
1600000110

错误原因

问题出在数据类型不匹配:你存储的shipmentid是数字类型(如6000001),但查询时使用了字符串类型的'6000001'。Dexie的查询遵循严格的类型匹配规则,只有当查询条件的类型与存储数据的类型完全一致时,才能匹配到所有符合条件的记录。当前查询只会匹配类型为字符串的shipmentid,导致仅返回一条结果。

修正后的查询代码

将查询条件中的字符串改为数字即可:

db.root.where({shipmentid : 6000001}).toArray().then((d)=>{
    console.log(d);
})

内容的提问来源于stack exchange,提问作者Badhusha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 18:45:40