2.8. 全局变量定义
全局变量是通过template.binding传入的变量,这些变量能在模板的任何一个地方,包括子模板都能访问到。如java代码里
template.binding("list",service.getUserList());
//在模板里
<%
for(user in list){
%>
hello,${user.name};
<% } %>
自从2.8.0版本后,有一个特殊的变量成为root变量,当模板找不到变量的时候,会寻找root变量的属性来作为变量的值,这个root变量必须绑定为"_root"
template.binding("_root",new User());
//在模板里
${name}
${wife.name}
这里name 和 wife都是User对象的属性
当前内容版权归 ibeetl.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ibeetl.com .