Dmi*_*rin 1 ejs node.js express cradle
我在我的博客上使用Cradle with Express和EJS.也许我错过了smth,但有些人将html实体转换为等价物.
我在doc.quote字段中有html,在这段代码之后它会改变
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);
});
});
Run Code Online (Sandbox Code Playgroud)
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>
<% } %>
Run Code Online (Sandbox Code Playgroud)
"res"变量是具有"content"字段(具有html)的对象的数组.但在渲染后,"str"将"quotes [i] .value.quote"符号转换为其实体,比如说to to< br>
Dmi*_*rin 10
答案在这里找到:http: //groups.google.com/group/express-js/browse_thread/thread/f488d19a1604c30e?pli = 1
<%=var%>
Run Code Online (Sandbox Code Playgroud)
用于逃避渲染
<%-var%>
Run Code Online (Sandbox Code Playgroud)
无需转义即可进行渲染