.net NVelocity宏参数未计算
我希望在NVelocity模板中创建一个内联函数(方法)。解决这个问题的办法似乎是使用。因此,我模拟了以下模板进行测试:.net NVelocity宏参数未计算,.net,vb.net,velocity,nvelocity,.net,Vb.net,Velocity,Nvelocity,我希望在NVelocity模板中创建一个内联函数(方法)。解决这个问题的办法似乎是使用。因此,我模拟了以下模板进行测试: #macro( getOutput $one $two $three ) <td>$one</td> <td>$two.Item2</td> <td>$three</td> #end <table> #foreach( $item in $mdl.Items ) <tr>
#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>
当我运行模板时,我遇到的问题是宏参数$three
的输出实际上是“$item.Item3”,而不是计算为#3/3/2003#。(顺便说一句,如果元组中的3个项目是通过.Item
调用传递的,则这会发生在其中的任何一个项目上,因此这与数据类型无关)
我可以创建一个变量,并将其很好地传递($one1)。我可以传递元组本身并调用宏($Item.Item2)中的.Item属性,但由于某些原因,在将参数传递给宏时,我无法调用
.Item
属性。有什么见解吗?看起来NVelocity宏支持有限
另一种方法是使用助手:
我也有同样的问题。你有没有找到解决办法?没有,我完全没有。我只是需要做些工作。
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