如何从领域过滤ID

时间:2019-05-30 07:28:45

标签: react-native realm

我试图像这样从Realm对象中过滤出一个ID:

let itemsInCart = realm.objects("Cart").filtered("id = " + itemId);

我的购物车模式如下:

export const CART_SCHEMA = "Cart";
export const CartSchema = {
  name: CART_SCHEMA,
  primaryKey: "id",
  properties: {
    id: "string",
    quantity: "int",
    productName: "string",
    productImage: "string"
  }
};

我想检查ID是否存在于我的Cart对象中,但是每当我尝试过滤出ID时,都会出现以下错误:

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试在Realm中按ID过滤对象

let itemsInCart = realm.objects("Cart").filtered("id == $0", itemId);