我需要在Dataweave中创建一个运行时变量,就像我们在Mule 3中使用using关键字一样。有人能让我知道如何在骡子4中实现
您仍然可以在Mule 4 / Dataweave 2中使用using
关键字。
局部变量在DataWeave脚本的主体中初始化,并且只能在初始化它们的表达式范围内通过名称引用。
初始化局部变量的语法如下所示:using(=)您可以将几个局部变量定义组合为using函数中的逗号分隔列表。例如:using(firstName ='Annie',lastName ='Point')
%dw 2.0
output application/json
---
using (x = 2) 3 + x
以下是在对象中定义局部变量的示例:
%dw 2.0
output application/xml
---
{
person: using (user='Greg', gender='male') {
name: user,
gender: gender
}
}
请注意,这些变量仅限于'person'对象。在人之外访问它们会引发错误。
关于此的完整文档:https://docs.mulesoft.com/mule-runtime/4.1/dataweave-variables