我如何在使用Dataweave的Anypoint Platform上将纯文本字符串输出到变量?

问题描述 投票:1回答:3

我感到迷失了方向,因为我无法弄清楚如何对对象进行迭代,连接纯文本字符串以及将结果输出到变量等简单的事情。这是我做过的类似的事情,效果很好:

%dw 2.0
output application/xml
var promptParams = attributes.queryParams filterObject($$ startsWith "PROMPT") orderBy($$)
---
{
RESULT: {
    Prompts: 
        promptParams mapObject(promptValue, promptName, index) -> {
            PROMPT: {
                UniquePromptName: promptName,
                FieldValue: promptValue
                }
        }
    }
}

因此,在这种情况下,我将过滤url查询字符串参数以仅获取我想要的参数,然后遍历这些参数并构造xml输出。我遇到的问题是,如果我尝试执行相同的操作但将纯文本字符串输出到变量,则无法进行任何操作。

基本上我要从此输入中输入:

https://example.com?PROMPT1=foo&PROMPT2=bar&PROMPT3=lorem&PROMPT4=ipsum&utm_source=Dolor&utm_campaign=SitAmet

将此输出存储在流变量中:

foo!bar!lorem!ipsum

我必须缺少一些基本的知识,因为要实现这一目标并不难。我在做什么错?

mule anypoint-studio dataweave
3个回答
3
投票

应该是这样的:

%dw 2.0
output text/plain
var promptParams = attributes.queryParams filterObject($$ startsWith "PROMPT")
---
promptParams pluck($) reduce ($$ ++ "!" ++ $)

输出:foo!bar!lorem!ipsum

您要求输入纯文本,但是如果您对流程中的变量有用,我建议您使用application / java。>>


2
投票
%dw 2.0
output text/plain
var promptParams = (((payload.message splitBy "?")[1]) splitBy "&") //stored url //in payload.message
---
promptParams map {
    a: ($ splitBy "=")[1]
}.a joinBy "!"

2
投票

您可以使用pluckjoinBy,如果正在使用转换消息组件,只需确保将目标设置为变量。

© www.soinside.com 2019 - 2024. All rights reserved.