在我下面给出的代码中,我无法在javascript中获得java arraylist值。我是java新手,玩框架请指导我。
/ *这是控制器代码* /
package controllers;
import play.*;
import play.mvc.*;
import views.html.*;
import play.data.*;
import java.util.List;
import java.util.ArrayList;
public class Application extends Controller {
public static Result playGraph() {
List<String> dashboardList = new ArrayList<String>();
dashboardList.add("{First Value}");
dashboardList.add("{Second Value}");
return ok(playGraph.render(dashboardList));
}
}
/****** The above controller code is working fine the problem is only in template******
/******Template page playGraph.scala.html ************/
@(dashboardList:List[String])
@main("All Graph") {
Size:@dashboardList.size()
<br>
1st Value: @dashboardList.get(0); <!--This line prints First Value-->
<br>
2nd Value: @dashboardList.get(1);<!--This line prints Second Value-->
<script>
alert(@dashboardList.size());//Alert shows 2
alert(@dashboardList.get(0)); // ==> Not working
</script>
}
在上面的代码中,我无法在javascript中获取@ dashboardList.get(0)值,但@ dashboardList.size()正在运行。