首页 > 解决方案 > 无法在我的领域数据库中检索项目数组

问题描述

我正在尝试从Item从我的本地数据库调用的表中检索一个数组,该表有我创建的大约 42 条记录,以便稍后查询和测试。但是,当我在按钮按下功能上请求数据时,我想看看数据是什么样子的。波纹管是我的组件:

const TestIndex = () => {
  const config = {
    schema: [ItemSchema],
  };

  const realm = new Realm(config);

  const onSaveItem = async () => {
    const items = await realm.objects("Item");

    return console.log(items);
  };


  return <Button buttonText="Save" buttonPress={onSaveItem} />;
}

我的架构如下:

export const ItemSchema = {
  name: "Item",
  properties: {
    _id: "objectId",
    itemCode: "string",
    itemDescription: "string",
    itemPrice: "string",
    partition: "string",
  },
  primaryKey: "_id",
};

当我运行该函数时,我期待一个包含我的数据的对象数组,但是当我得到这个时console.log(items)

Proxy {isRealmCtor: true}
[[Handler]]: Object
get: ƒ ()
arguments: null
caller: null
length: 0
name: ""
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[Scopes]]: Scopes[0]
getOwnPropertyDescriptor: ƒ ()
getPrototypeOf: ƒ ()
has: ƒ ()
ownKeys: ƒ ()
set: ƒ ()
setPrototypeOf: ƒ ()
__proto__: Object
[[Target]]: Results
[[IsRevoked]]: false

这是一张图片,可以更好地理解结果: 错误图像

标签: react-nativerealm

解决方案


推荐阅读