我有一个结果作为列表
[[<a onclick="viewEmpDetails('563291f0af6a1ecb740f904c','false','UniqueId')" title='View' style='cursor:pointer'><i class='ace-icon fa fa-search-plus grey' style='width:30px;'> </i></a>, 02/02/49, 02/02/49, 02/02/1949, 11-Jan-1916, 10-Feb-33]]
我正在使用下面的代码进行迭代
<g:each in="${session.treeGridJsonObject}" var="lists">
<g:each in="${lists}" var="list">
<td>${list}</td>
</g:each>
</g:each>
我如何在 Controller 中添加 html 数据
htmlData += "<a onclick=\"viewEmpDetails('"+row['UniqueId']+"','false','UniqueId')\" title='View' style='cursor:pointer'><i class='ace-icon fa fa-search-plus grey' style='width:30px;'> </i></a>"
当我尝试调试时显示双“”引号。
最佳答案
这是为了防止XSS attacks .这样,如果用户提交了一些 javascript,它不会在显示给其他人时运行。原始数据的输出有多种方式:
${raw(content)}
或
${content.encodeAsRaw()}
或
<g:encodeAs codec="Raw">${content}</g:encodeAs>
或
<g:encodeAs codec="None">${content}</g:encodeAs>
参见 http://mrhaki.blogspot.nl/2013/11/grails-goodness-generating-raw-output.html
关于html - 为什么 HTML 显示为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33434216/