Rou*_*ouz 0 javascript frontend underscore.js underscore.js-templating
基本上我要做的是使用下划线js编译带有一些数据的模板.我的代码如下:
var temp = "<div> Hello <%=names%> </div>";
var html = _.template(temp, {names:'world'};
Run Code Online (Sandbox Code Playgroud)
我期待我的变量html
<div> Hello world </div>
Run Code Online (Sandbox Code Playgroud)
但由于某些原因,变量名称未定义,而编译和模板永远不会编译.
这是下划线js最基本的东西,根据文档和Web上的大量示例,它应该工作.我究竟做错了什么?
该_.template功能已经改变了一点点,假设你的最新版本,它现在生产的功能,而不是你有你要显示的数据调用编译HTML.
var temp = "<div> Hello <%= names %> </div>";
var html = _.template(temp);
console.log(html({names:'world'}));
"<div> Hello world </div>"
Run Code Online (Sandbox Code Playgroud)