我想过滤数组列表索引并根据我提供的 docid 过滤文档。
下面的代码适用于第 0 个索引,但无法搜索整个列表并找出 docid
var results =
this._items?.userItems?.filter { it -> it.requests.get(0).doc == docid }
请提出更好的方法。
非常感谢任何帮助
谢谢
最佳答案
假设您只想保留具有给定 docid
的任何请求
的userItems
,则可以使用它。 requests.any { request -> request.doc == docid }
.
来自documentation (请参阅接受谓词的重载):
Returns true if at least one entry matches the given predicate.
如果您想获取具有给定docid
的所有请求
,您可以使用:userItems.flatMap { it.requests }.filter { it .doc == docid }
关于kotlin - 根据字符串值动态过滤数组列表 - kotlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74219737/