日期:2014-05-16  浏览次数:20289 次

jsp里的${}和jquery template的${} 怎么样转义

ttp://www.infoq.com/cn/news/2010/10/jQuery-Template?

http://api.jquery.com/category/plugins/templates/

ms发布的jquery模板插件
在这个插件里他使用的变量占位符和jsp的el表达式用的是一样的${}, 所以在用jsp作为服务器端的输出时要进行转义, 不然jsp会把原本是属于jquery模板插件的变量也进行了替换. 以下介绍两种方式

?

1. escapse ${} in JSP page

<script id="clientTemplate" type="text/html">
<li><a href="clients/${id}">${name}</a></li>
</script>
?

进行转义后

<script id="clientTemplate" type="text/html">
<li><a href="clients/${'${'}id}">${'${'}name}</a></li>
</script>

?
2. save jQuery template as separated file and disable its EL evaluation

if you have a lot of jQuery templates, it's better to extract them out to a seperated file. 不使用el表达式

<%@ page isELIgnored="true" %>
<script id="clientTemplate" type="text/html">
<li><a href="clients/${id}">${name}</a></li>
</script>
<script id="anotherTemplate" type="text/html">
<li><a href="clients/${id}">${name}</a></li>
</script>

?


Then include this file in your JSP pages need template:

<jsp:include page="jqTemplate.jsp"></jsp:include>

?
======================================================

http://www.infoq.com/cn/news/2010/10/DataLink-jQuery? Data Link:jQuery的数据绑定插件


http://code.google.com/p/jquery-utils/? jquery 工具集, 包含字符串格式化处理, cookie, 数组, 国际化处理.

1 楼 tonyseek 2011-04-06  
可以直接在 JQuery Template 用 {{= data}}(注意空格) 代替 ${data}