简体   繁体   English

将字典对象与 Parse.com 中的数组进行比较 - iOS

[英]Compare dictionary object with an Array in Parse.com - iOS

I have a class that has a object type column, eg我有一个具有对象类型列的类,例如

          COLUMN 1
Row 1 :   {"gender":"male","name":"A"}
Row 2 :   {"gender":"female","name":"B"}
Row 3 :   {"gender":"male","name":"C"}

I need to get the rows whose objects for key name , in COLUMN1, matches the contents of my array ["A","B"]我需要在 COLUMN1 中获取 key name的对象与我的数组["A","B"]的内容匹配的行

So in may case, query should return ROW 1 and ROW 2.所以在可能的情况下,查询应该返回 ROW 1 和 ROW 2。

I know this method but its for comparing array with a string column in Parse, as far as I know: [query whereKey:@"name" containsAllObjectsInArray:selectedParticipants];我知道这种方法,但它用于将数组与 Parse 中的string列进行比较,据我所知: [query whereKey:@"name" containsAllObjectsInArray:selectedParticipants];

How to compare my array with a dictionary column?如何将我的数组与字典列进行比较?

One of the disadvantages of the object type in a parse.com collection is that it can only be queried for an exact match. parse.com 集合中对象类型的缺点之一是它只能查询完全匹配。 The only way to do this under your current model is to qualify the query with the other columns to get back the smallest set that might match on the object criterion, then do the object matching on the client side.在当前模型下执行此操作的唯一方法是使用其他列限定查询以取回可能与对象标准匹配的最小集合,然后在客户端进行对象匹配。

If the collection has a lot of documents, and you want this to run fast, the better choice is to adjust the data model so the query-able properties in the embedded objects are their own columns...如果集合有很多文档,并且您希望它快速运行,则更好的选择是调整数据模型,以便嵌入对象中的可查询属性是它们自己的列...

       name (string) gender (string) otherStuff (object)
row0   "A"           "male"          { /* stuff we don't query on */ }
row1   "B"           "female"        { ... }
...

With that, you would use [query whereKey:@"name" containedIn:@[@"A", @"B"]] to qualify the query.这样,您将使用[query whereKey:@"name" containedIn:@[@"A", @"B"]]来限定查询。 Notice this is not containsAllObjectsInArray, which is how to test an array property.注意这不是 containsAllObjectsInArray,它是测试数组属性的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM