play 2.0模板引擎是否支持html页面中的简单计算。
比方说,我创建了一个sum.scala.html页面:
@(a:String, b: String)
<html>
<head></head>
<body>
<h1> answer is getSum(@a,@b) </h1>
</body>
</html>有没有办法通过一些函数来"getSum of a and b“呢?或者,任何play 2.0专家对play 2.0模板引擎中的计算有什么好的想法吗?谢谢
发布于 2012-04-05 16:59:08
你试过@(a.toInt + b.toInt)吗?
发布于 2012-04-05 16:19:42
你可以直接把值传递给模板,不是吗?
@(a:String, b: String, c: String)
<h1> answer for @a + @b is @c </h1>您也可以在模板中从Yourcontroller调用函数:
@Yourcontroller.getSum(a,b);在/app/controllers/Yourcontroller.java ad中的函数(最简单的示例):
public static Integer getSum(String a, String b){
Integer c = Integer.valueOf(a) + Integer.valueOf(b);
return c;
}发布于 2012-04-05 20:42:08
如果想要多次引用结果,可以使用defining
@defining(a.toInt + b.toInt) { sum =>
<h1>The sum is @sum</h1>
The sum of @a + @b is @sum
}https://stackoverflow.com/questions/10024880
复制相似问题