英文:
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
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论