【问题标题】:How to get the first value from an Array after split String in Data weave?在Dataweave中拆分字符串后如何从数组中获取第一个值?
【发布时间】:2021-02-19 10:01:08
【问题描述】:

我试图在拆分字符串后比较字符串数组中的第一个值。 但是我的子函数抛出错误说它接收一个数组,我做错了什么。

fun getErrorList() =
compareAddress(loanData.loan.propertyAddress,payload.propertyAddress)
fun compareAddress(loanpropertyAddress, inputPropertyAddress) =
if(null != loanpropertyAddress and null != inputPropertyAddress)
getAddr1 (loanpropertyAddress splitBy(" "))[0]
==
getAddr1 (inputPropertyAddress splitBy(" "))[0]
else
null

fun getAddr1(addr1) =
addr1 replace "#" with ("")

【问题讨论】:

    标签: dataweave mule4


    【解决方案1】:

    问题在于您如何调用 getAddr1 函数。在您提供的 DataWeave 表达式中,您将字符串数组而不是字符串传递给 getAddr1 函数:

    ...
    getAddr1(
        loadpropertyAddress splitBy(" ") // splitBy returns an array of strings
    )[0] // here, you're trying to get the first element of the value returned by getAddr1
    ...
    
    

    我假设您在删除“#”字符后尝试比较贷款的第一部分和输入的财产地址。如果我的理解是正确的,那么您可以对您的功能进行以下更改:

    ...
    getAddr1(
        loadpropertyAddress splitBy(" ")[0] // get the first element of the string array returned by the splitBy function
    ) // removed array item selector ([0])
    ...
    

    修改后,您的 DataWeave 表达式应如下所示:

    fun getErrorList() =
    compareAddress(loanData.loan.propertyAddress,payload.propertyAddress)
    fun compareAddress(loanpropertyAddress, inputPropertyAddress) =
    if(null != loanpropertyAddress and null != inputPropertyAddress)
    getAddr1 (loanpropertyAddress splitBy(" ")[0])
    ==
    getAddr1 (inputPropertyAddress splitBy(" ")[0])
    else
    null
    
    fun getAddr1(addr1) =
    addr1 replace "#" with ("")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-13
      相关资源
      最近更新 更多