使用来自其他变量的元素初始化数组变量的正确语法是什么?我尝试过:
#include <iostream>
using namespace std;
namespace nmp1
{
float foo = 100;
}
namespace nmp2
{
float foo = -22;
}
int main(int, char**) {
using namespace nmp1;
using nmp2::foo;
cout << foo << endl;
}
还有一个"Initialize_variable_AllEventCounts": {
"inputs": {
"variables": [
{
"name": "AllEventCounts",
"type": "Array",
"value": "[@{variables('EmailConfirmedFailureEventCount')}, @{variables('EmailConfirmedSuccessEventCount')}, @{variables('UserCreatedEventCount')}, @{variables('UserLoginFailureEventCount')}, @{variables('UserLoginSuccessEventCount')}, @{variables('UserLogoutSuccessEventCount')}]"
}
]
},
"runAfter": {
"Set_variable_EmailConfirmedFailureEventCount": [
"Succeeded"
],
"Set_variable_EmailConfirmedSuccess": [
"Succeeded"
],
"Set_variable_UserCreatedEventCount": [
"Succeeded"
],
"Set_variable_UserLoginFailureEventCount": [
"Succeeded"
],
"Set_variable_UserLoginSuccessEventCount": [
"Succeeded"
],
"Set_variable_UserLogoutSuccessEventCount": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
表达式没有提供我期望的结果:
createArray()
更新: 上面的createArray()语法接近正确。正确的语法如下:
"value": "@{createArray(variables('EmailConfirmedFailureEventCount'), variables('EmailConfirmedSuccessEventCount'), variables('UserCreatedEventCount'), variables('UserLoginFailureEventCount'), variables('UserLoginSuccessEventCount'), variables('UserLogoutSuccessEventCount'))}"
答案 0 :(得分:0)
有一个Union action,您可以用它来组合多个数组。
"Initialize_variable_4": {
"inputs": {
"variables": [
{
"name": "array4",
"type": "Array",
"value": "@union(variables('array1'),variables('array2'),variables('array3'))"
}
]
},
"runAfter": {
"Initialize_variable_3": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
答案 1 :(得分:0)
答案很简单。 createArray()表达式按预期工作。在我较大的Logic App中一定是其他语法错误,使我觉得数组初始化中存在语法错误。
要回答我自己的问题,我创建了一个空的Logic App来测试这件事:
该示例Logic App的完整代码如下:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_Array1_=_[Var1,_Var2]": {
"inputs": {
"variables": [
{
"name": "Array1",
"type": "Array",
"value": "@createArray(variables('Var1'), variables('Var2'))"
}
]
},
"runAfter": {
"Initialize_Var2_=_3": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_Var1_=_2": {
"inputs": {
"variables": [
{
"name": "Var1",
"type": "Integer",
"value": 2
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_Var2_=_3": {
"inputs": {
"variables": [
{
"name": "Var2",
"type": "Integer",
"value": 3
}
]
},
"runAfter": {
"Initialize_Var1_=_2": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"Recurrence": {
"recurrence": {
"frequency": "Minute",
"interval": 3
},
"type": "Recurrence"
}
}
}
}