如何在 aws appsync 解析器中使用“$util.list.copyAndRetainAll(List, List)”?
How to use "$util.list.copyAndRetainAll(List, List)" in aws appsync resolvers?
List helpers in $util.list 简要提到了 copyAndRetainAll(List, List): List
。
尽管有描述,但我不太确定 'retaining only the items specified' 是什么意思。第二个列表实际上是一个集合吗?它是否按顺序遍历两个列表? return 将两个列表转换为集合后是否是公共元素?
有没有人有这方面的一些实际例子?
让我们将方法定义为$util.list.copyAndRetainAll(List1, List2) : List3
,只是为了更容易识别不同的列表。
List3
将是 List1
的副本,但是,List3
将被过滤为仅包含 List2
中存在的元素。举个例子可能会更清楚:
List1 = [1, 2, 3]
List2 = [2, 3, 4]
List3 = [2, 3]
List3
是List1
的副本,但是List2
只包含2
、3
和4
,所以我们去掉所有其他元素,在本例中为 1
,来自 List1
,并留下 [2, 3]
作为 List3
.
的值
List helpers in $util.list 简要提到了 copyAndRetainAll(List, List): List
。
尽管有描述,但我不太确定 'retaining only the items specified' 是什么意思。第二个列表实际上是一个集合吗?它是否按顺序遍历两个列表? return 将两个列表转换为集合后是否是公共元素?
有没有人有这方面的一些实际例子?
让我们将方法定义为$util.list.copyAndRetainAll(List1, List2) : List3
,只是为了更容易识别不同的列表。
List3
将是 List1
的副本,但是,List3
将被过滤为仅包含 List2
中存在的元素。举个例子可能会更清楚:
List1 = [1, 2, 3]
List2 = [2, 3, 4]
List3 = [2, 3]
List3
是List1
的副本,但是List2
只包含2
、3
和4
,所以我们去掉所有其他元素,在本例中为 1
,来自 List1
,并留下 [2, 3]
作为 List3
.