我有一个下面的函数来检查字符串并删除值。 当字符串与大小写准确匹配时,它工作正常。我试图添加 lower 以检查给定字符串中的两种可能性。但它没有按预期工作。
if filterList = "phone, email" 它只删除与 "phone" 完全匹配的键和值。如果字符串是“Phone”,它不会被删除。
%dw 1.0
%output application/json skipNullOn="everywhere"
%function remove(content, filterList)
content match {
:array -> $ map (value,index) -> remove(value, filterList),
:object -> $ mapObject (value,key) ->
(key): null when (filterList contains (lower key as :string))
otherwise remove(value, filterList)
,
default -> null when ((content !=null) and (filterList contains content as :string)) otherwise content
}