0

我是 Velocity 的新手,找不到解决这个问题的方法,所以如果它是微不足道的,我深表歉意。假设我有以下 200 个变量。

  #set( $a1 = "apple", $b1 = "red", $a2 = "banana", $b2 = "yellow" .... 
       .... $a100 = "plum", $b100 = "purple)

我想输出水果,然后是它的颜色。有没有办法将“a”和“b”与范围(1,100)中的每个数字连接起来,然后取消引用变量?就像是

 #foreach( $i in [1..100])
     #set( $fruit = "a{$i}")
     #set( $color = "b{$i}")

     The fruit $fruit is the color $color. 

 #end

我尝试了很多事情,但只能设法将 $a1 $b1 输出为字符串,而不是它们所指的内容。谢谢!

4

1 回答 1

3
#set ($d = '$')
#set ($h = '#')
#foreach ($i in [1..100])
  #evaluate("${h}set(${d}fruit = ${d}a${i})")
  #evaluate("${h}set(${d}color = ${d}b${i})")
  The fruit ${fruit} is the color ${color}.
#end
于 2013-08-01T15:15:32.103 回答