【问题标题】:How to Query pinned ParseObjects of different subclasses?如何查询不同子类的固定 ParseObjects?
【发布时间】:2016-01-14 06:27:05
【问题描述】:
我正在尝试在我的应用程序上创建一种“最近查看”功能。用户类有一个数组类型的列,我在其中存储指向 不同子类的 ParseObjects 的指针。
例如,
- 我有一个名为 Offers 的 ParseObject,我有另一个 ParseObject
称为 Products 的不同子类。
- 用户对象类中名为“RecentlyViewedItems”的数组包含这两种类型。
- 我在应用程序中获取该数组并将它们固定在本地。
- 我需要从固定列表中检索它们,我通常从
使用 ParseQuery 固定列表。但是这个特定的固定列表包含
不同类的 ParseObjects,据我所知 ParseQuery
只使用指定的子类,而不是泛化的 ParseObject。
那么,我如何从不同类型 ParseObjects 的固定列表中检索项目?
【问题讨论】:
标签:
java
android
parse-platform
【解决方案1】:
来自 pin 的查询类似于来自 parse 的查询。区别仅在于设置属性query.fromPin();
因此,如果您的 pin 命名为 "RecentlyViewedItems",您的查询应如下所示:
ParseQuery<ParseObject> query = ParseQuery.getQuery("Offers");
query.fromPin("RecentlyViewedItems");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " scores");
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
More info...