使用 mustache.js 制作 table

using mustache.js to make table

我正在从数据库中获取数据,将它们放在 HTML table 中。然后将其发送到 html 文件:

listAllResults(function (VariableWithNoName){
    console.log ( 'getting the data ' ) ;
    res.render('addPlaces', {title: 'addPlaces', places_list: VariableWithNoName}); 
});   

VariableWithNoName是table,table是这样生成的:

show = show + '<tr><td>' + result['BasicInfo[Name]'] + '</td></tr>';

它是由回调发送的。但是在页面中它显示了结果,但是显示了 html 代码,例如:

<table><tr><td>Some name</td></tr><tr><td>Øyvinds Cuban Casa</td></tr></table>

而不是 table 数据。

如果不能查看您的模板,我无法确定,但我相信这是在模板中取消转义 html 的问题(这可以通过使用 3 个大括号而不是 2 个大括号来完成)。

All variables are HTML-escaped by default. If you want to render unescaped HTML, >use the triple mustache: {{{name}}}. You can also use & to unescape a variable.

https://github.com/janl/mustache.js/

(可能重复Text as HTML in Mustache.js