我正在寻找在我的NVelocity模板内创建一个内联函数(方法)。解决方案似乎是使用Velocimacros。所以,我嘲笑了下面的模板测试:NVelocity宏参数没有评估
#macro(getOutput $one $two $three)
<td>$one</td>
<td>$two.Item2</td>
<td>$three</td>
#end
<table>
#foreach($item in $mdl.Items)
<tr>
#set($one1 = $item.Item1)
#getOutput($one1 $item $item.Item3) ## item.Item3 won't evaluate!
</tr>
#end
</table>
$mdl
是我的基本型号的对象,在这个例子中包含一个属性,Items
,这是一个List(Of Tuple(Of String, Integer, Date))
。用测试数据填充像这样:
Dim items As New List(Of Tuple(Of String, Integer, DateTime))
With items
.Add(New Tuple(Of String, Integer, DateTime)("One", 1, #1/1/2001#))
.Add(New Tuple(Of String, Integer, DateTime)("Two", 2, #2/2/2002#))
.Add(New Tuple(Of String, Integer, DateTime)("Three", 3, #3/3/2003#))
End With
当我运行模板,我遇到的问题是,从宏观参数$three
输出字面意思是“$ item.Item3”,而不是计算到#3 /二千○三分之三#。 (顺便说一句,如果元组通过.Item
调用传递,则元组中的任何元素都会发生这种情况,所以它不是数据类型)。
我可以做一个变量,并通过它就好($ one1)。我可以传递元组本身并调用宏($ item.Item2)中的.Item属性,但由于某种原因,我无法在将参数传递给宏时调用.Item
属性。任何见解?
我有同样的问题。你有没有找到解决方案? – KClough 2011-11-16 15:21:20
不,我完全没有。我只需要做一些工作。 – mattmc3 2011-11-17 14:52:00