使用数组引用扩展符([*])来解构嵌套的数组。
在 ARM 模板中,数组引用扩展符([*])用于解构数组并扩展其元素。可使用此符号将嵌套的数组展开为平面数组。例如,假设我们有以下嵌套数组:
"myArray": [
[ "a", "b", "c" ],
[ "d", "e", "f" ]
]
若要将其展开为平面数组,可使用下面的表达式:
"flattenedArray": "[union(variables('myArray')[*])]"
在此示例中,“[*]” 在嵌套数组中引用了所有子数组。union() 函数将它们组合在一起并生成包含所有数组元素的平面数组。
完整的代码示例如下:
{
"variables": {
"myArray": [
[ "a", "b", "c" ],
[ "d", "e", "f" ]
]
},
"resources": [
{
"name": "example",
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2021-04-01",
"location": "[resourceGroup().location]",
"properties": {
"storageProfile": {
"dataDisks": [
{
"name": "disk1",
"diskSizeGB": 1,
"lun": 0,
"createOption": "Empty",
"caching": "None",
"diskIOPSReadWrite": 100,
"diffDiskSettings": {
"option": "Local"
},
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
},
{
"name": "disk2",
"diskSizeGB": 2,
"lun": 1,
"createOption": "Empty",
"caching": "None",
"diskIOPSReadWrite": 200,
"diffDiskSettings": {
"option": "Local"
},
"managedDisk": {
"storageAccountType": "Premium_LRS"
}
}
]
}
}
}
]
}