我在我的博客上使用了Cradle和Express和EJS。也许我错过了smth,但他们中的一些人将html实体转换为它的等价物。
我在doc.quote字段中有一个超文本标记语言,在这段代码之后它会改变
quotesDb.view('list/by_date', {
'startkey' : {},
'endkey' : null,
'descending' : true
}, function(err, res) {
if (err) {
r.send();
return;
}
r.partial('quotes', {'quotes' : res}, function(err, str) {
console.log(str);
sendResponse('content', str);
});
});quotes.ejs:
<% for (var i=0; i<quotes.length; i++) { %>
<div>
<%=quotes[i].value.quote%>
</div>
<div class="date">
<%=(new Date(quotes[i].value.ts*1000)).toLocaleDateString()%><% if (quotes[i].value.author) { %>, <%=quotes[i].value.author%><% } %>
</div>
<% } %>"res“变量是具有带有"content”字段(具有html)的对象的数组。但在渲染"str“后,将"quotesi.value.quote”符号转换为其实体,例如<;br >;
发布于 2011-09-14 20:25:26
答案可以在这里找到:http://groups.google.com/group/express-js/browse_thread/thread/f488d19a1604c30e?pli=1
对于带有转义的渲染:
<%=var%>对于不进行转义的渲染:
<%-var%>https://stackoverflow.com/questions/7415641
复制相似问题