从数组中删除特定元素在Velocity模板语言(VTL)中的操作:

huangapple go评论71阅读模式
英文:

Remove certain element from array in Velocity Template Language (VTL)

问题

我想从Velocity模板语言的数组中移除特定元素。在查阅了Apache VTL的文档后,我没有找到合适的方法,所以我在这里寻求帮助。我尝试了以下方法(`.remove()` 似乎不是数组元素的方法):

#set($linkedWIARRAY = ["ABC-123, DEF-345, GHI-678"])

#set($dummy=$linkedWIARRAY.add("JKL-901"))

#set($dummy = $linkedWIARRAY.remove("DEF-345"))

$linkedWIARRAY

$linkedWIARRAY 返回 [ABC-123, DEF-345, GHI-678, JKL-901],显示 `remove` 很可能不是数组的方法 ;)

在Stack Overflow上有一个类似的问题,但对我没有帮助:
https://stackoverflow.com/questions/42378967/velocity-template-drop-element-from-array
英文:

I would like to remove a certain element from an array in Velocity Template Language. I did not find any appropriate method looking through the documentation of Apache VTL, that's why I am asking here for help. I have tried following (.remove() doesn't seem to be a method on array items):

#set($linkedWIARRAY = ["ABC-123, DEF-345, GHI-678"])

#set($dummy=$linkedWIARRAY.add("JKL-901"))

#set($dummy = $linkedWIARRAY.remove("DEF-345"))

$linkedWIARRAY

$linkedWIARRAY returns [ABC-123, DEF-345, GHI-678, JKL-901], showing that remove very likely doesn't exist as method on arrays 从数组中删除特定元素在Velocity模板语言(VTL)中的操作:

There is a similar question on SO, that didn't help me:
https://stackoverflow.com/questions/42378967/velocity-template-drop-element-from-array

答案1

得分: 3

问题出在列表的初始化上。应该是:

#set($linkedWIARRAY = ["ABC-123", "DEF-345", "GHI-678"])

也就是说,每个字符串都应该用双引号括起来,而不是整个字符串。

英文:

The problem lies in the initialization of the list. It should be:

#set($linkedWIARRAY = ["ABC-123", "DEF-345", "GHI-678"])

that is, each string should be enclosed in double quotes, not the whole string.

huangapple
  • 本文由 发表于 2020年9月25日 16:34:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/64060641.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定