首页 > 解决方案 > “何时和其他”条件的问题

问题描述

我会让代码做解释。

Dataweave 给出错误:

无法解析何时参考

无法解决其他参考

输入消息:对象数组。虽然我在这里只给出了 1 个对象。

[{
    "Field1" : 12345,
    "field2" : 10
}]
%dw 2.0
output application/json
---
payload map {
"test" : $.Field1 when $.field2 >= 1 otherwise ""
}

标签: mulemule-studiodataweavemulesoftmule-esb

解决方案


<expression> when <condition> otherwise <expression>Nadeem在 DW 2.0中没有。改为使用if (condition) <then_expression> else <else_expression>

所以你的代码如下:

%dw 2.0
output application/json
var data = [{
    "Field1" : 12345,
    "field2" : 10
}]
---
data map {
    test : if  ($.field2 >= 1) $.Field1 else ""
}

推荐阅读