如何在速度模板中附加哈希表? [英] How to append hash tables in velocity template?

查看:27
本文介绍了如何在速度模板中附加哈希表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以速度附加两个哈希表.

I tried to append two hash tables in velocity.

#foreach($dun1 in $dotcontent.pull("+structureName:Checnas +(conhost:fe1d98e8-9699-4f3f-abf5-a6c0afc8ab47 conhost:SYSTEM_HOST)",10,"modDate desc"))
#set($foo={
    $!{dun1.mname}:$!{dun1.subname} 
})
#end

在上面的每个循环中,我从结构Checnas"中提取内容.但最后我们只能得到内容中的最后一个值.为了解决我们需要为每次迭代追加的问题.我需要追加哈希表的语法.请帮我解决这个问题.

In the above for each loop I am pulling content from structure "Checnas". But at the end we can get only the last value in the content.To solve that we need to append for every iteration.I need syntax for appending hash tables. Please help me to solve this.

推荐答案

您的代码当前每次都在写 $foo,因此您只是获得最后一个值.您可以在速度中使用列表来实现这一点.这可能有效:

Your code currently is over writing $foo each time and hence you are just getting the last value. You can use lists in velocity to achieve this. This might work:

#set($listOfMnames=[])
#set($listOfSubNames=[])

#foreach($dun1 in $dotcontent.pull("+structureName:Checnas +(conhost:fe1d98e8-9699-4f3f-abf5-a6c0afc8ab47 conhost:SYSTEM_HOST)",10,"modDate desc"))
#set($foo=$listOfMnames.add($!{dun1.mname}))
#set($foo=$listOfSubNames.add($!{dun1.subname}))
#end

这样,您将得到两个完全填充的列表listOfMnames"和listOfSubNames".您可以稍后遍历它们以打印/使用它们的值.

This way, you will end up with two lists 'listOfMnames' and 'listOfSubNames', both fully populated. You can later iterate through them to print/utilise their values.

此链接会有帮助并告诉你使用 $foo 的目的,它没有被使用,只是被分配了.或者,您也可以使用具有适当键/值对的速度映射,但一定要在循环开始之前声明它.

This link will be helpful and tell you the purpose of using $foo which is not being used and just being assigned. Alternatively, you can also use velocity maps with proper key/val pairs but be sure to declare it before the loop begins.

这篇关于如何在速度模板中附加哈希表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆