本文介绍了React Native领域,如何查询列表对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到了这个问题(使用React Native领域通过多个列表对象进行查询),但无法获取我的查询可以使用@ blackpla9ue提供的答案.

I noticed this question (Use React Native Realm to Query through multiple List Objects) but was unable to get my query to work with the provided answer from @blackpla9ue.

我具有以下架构/模型,我想查询ProductReview-> productId等于123,并且Review-> reviewText包含简单字符串"的地方.

I have the following schemas/models, and I want to query where ProductReview->productId is equal to 123, and Review->reviewText contains "a simple string".

此查询仅返回productId 123的所有评论.

This query simply returns all reviews for productId 123.

let allReviews = realm.objects('ProductReview', 'productId = "123");
let reviews = allReviews.filtered('reviews.reviewText CONTAINS[c] "a simple string"');

我还尝试了删除'productId = "123"',这只会导致返回所有产品的所有产品评论.似乎是完全忽略了filtered或我缺少了某些内容.

I have also tried removing 'productId = "123"' which simply results in all product reviews being returned for all products. It seems to either be completely ignoring filtered or I am missing something.

class ProductReview extends Realm.Object{}
ProductReview.schema = {
  name: 'ProductReview',
  primaryKey: 'productId',
  properties: {
      productId: 'string',
      averageRating: 'float',
      totalReviewCount: 'int',
      reviews: {type: 'list', objectType: 'Review'},

  }
}

class Review extends Realm.Object{}
Review.schema = {
   name: 'Review',
   properties: {
     rating: 'float',
     title: {type: 'string', optional: true},
     reviewText: {type: 'string', optional: true},
     userLocation: {type: 'string', optional: true},
     userNickName: {type: 'string', optional: true},
     tags: {type: 'list', objectType: 'StringList'}
   }
}

希望在这里查看我可能做错了什么.

Looking to see what I might be doing wrong here.

谢谢!

推荐答案

根据 the文档,在我看来,您可能正在寻找的查询是

According to the docs, it seems to me that the query you're possibly looking for is

let allReviews = realm.objects('ProductReview');
let reviews = allReviews.filtered(
                 'productId = "123" AND reviews.reviewText CONTAINS[c] "a simple string"');

这篇关于React Native领域,如何查询列表对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 08:48