collections.Merge
Syntax
collections.Merge MAP MAP...
Returns
any
Alias
merge
返回从左到右合并两个或多个映射的结果。如果键已经存在,merge
将更新其值。如果键不存在,merge
将在新键下插入值。
键的处理是大小写不敏感的。
以下示例使用这些映射定义:
{{ $m1 := dict "x" "foo" }}
{{ $m2 := dict "x" "bar" "y" "wibble" }}
{{ $m3 := dict "x" "baz" "y" "wobble" "z" (dict "a" "huey") }}
示例 1
{{ $merged := merge $m1 $m2 $m3 }}
{{ $merged.x }} → baz
{{ $merged.y }} → wobble
{{ $merged.z.a }} → huey
示例 2
{{ $merged := merge $m3 $m2 $m1 }}
{{ $merged.x }} → foo
{{ $merged.y }} → wibble
{{ $merged.z.a }} → huey
示例 3
{{ $merged := merge $m2 $m3 $m1 }}
{{ $merged.x }} → foo
{{ $merged.y }} → wobble
{{ $merged.z.a }} → huey
示例 4
{{ $merged := merge $m1 $m3 $m2 }}
{{ $merged.x }} → bar
{{ $merged.y }} → wibble
{{ $merged.z.a }} → huey