如何对ParseObjects列表中的每个项目执行ParseQuery

时间:2019-06-11 10:23:56

标签: android kotlin parse-platform

我想在Kotlin中进行ParseAPI调用,其中输入为List<ParseObject>,输出为更新MutableList<CustomObject>,其中CustomObject是包含ParseObjectInt的数据类。我可以做这样的事情:

var newItems = mutableListOf<CustomObject>()
items.forEach{
//do query on relation column of item
//inside query.findInBackground -> (if error == null) add item to newItems
}

但是当新列表完成时,我需要调用回调函数。我需要类似await函数的调用。因为我必须等到每个项目的回调结束后才能将结果返回给Activity。

这意味着查询功能的定义如下:

fun getCurrentItems(c: Context, items: List<ParseObject>, callback:(MutableList<CustomObject>) -> Unit)

如果所有项目都被选中,我只想打电话给

callback(newItems)

0 个答案:

没有答案