【问题标题】:how to get single column data from Dexiejs indexedDB table如何从 Dexiejs indexedDB 表中获取单列数据
【发布时间】:2021-07-06 17:29:37
【问题描述】:

如何只从每一行获取价格

db -
    [{
        "id": 1,
        "name": "name 2",
        "price": 40,
        "img": "img.jpeg",
        "isActive": true
    }, {
        "id": 2,
        "name": "name 2",
        "price": 60,
        "img": "img.jpeg",
        "isActive": true
    }]

目前在db.product.toArray() 的帮助下,我能够获取所有数据。

但我想要 Dexiejs indexedDB 中的 [40, 60]。

【问题讨论】:

    标签: javascript arrays dexie dexiejs


    【解决方案1】:

    如果你索引price,你可以使用Collection.keys()

    const db = new Dexie('yourDBName');
    db.version(2).stores({
      product: 'id, price'
    });
    
    const prices = await db.product.orderBy('price').keys();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 2012-05-21
      • 1970-01-01
      • 2018-11-23
      相关资源
      最近更新 更多