Javascript 下划线.js模板编译

Javascript 下划线.js模板编译,javascript,underscore.js,frontend,underscore.js-templating,Javascript,Underscore.js,Frontend,Underscore.js Templating,基本上,我要做的是使用下划线js编译带有一些数据的模板。我的代码如下: var temp = "<div> Hello <%=names%> </div>"; var html = _.template(temp, {names:'world'}; var temp=“你好”; var html=u2;.template(temp,{names:'world'}; 我希望我的变量html是 <div> Hello world </div&

基本上,我要做的是使用下划线js编译带有一些数据的模板。我的代码如下:

var temp = "<div> Hello <%=names%> </div>";
var html = _.template(temp, {names:'world'};
var temp=“你好”;
var html=u2;.template(temp,{names:'world'};
我希望我的变量html是

<div> Hello world </div> 
你好,世界
但由于某些原因,当编译和模板从不编译时,变量名是未定义的

这是下划线js最基本的功能,根据web上的大量示例,它应该可以工作。我做错了什么?

有一点变化,假设您使用的是最新版本,它现在生成一个函数,而不是编译后的HTML,您必须使用要显示的数据调用它

var temp = "<div> Hello <%= names %> </div>";
var html = _.template(temp);
console.log(html({names:'world'}));

"<div> Hello world </div>"
var temp=“你好”;
var html=u2;模板(temp);
log(html({names:'world}));
“你好,世界”
有一点变化,假设您使用的是最新版本,它现在会生成一个函数,而不是您必须使用要显示的数据调用的已编译HTML

var temp = "<div> Hello <%= names %> </div>";
var html = _.template(temp);
console.log(html({names:'world'}));

"<div> Hello world </div>"
var temp=“你好”;
var html=u2;模板(temp);
log(html({names:'world}));
“你好,世界”

你刚刚救了我的命……没问题,黑客快乐!:)你刚刚救了我的命……没问题,黑客快乐!:)