我正在使用 _.template
Lodash 函数,想知道如何自定义传递给它的数据值。我只想做一些类似的事情(参见 toUpperCase()):
var compiled = _.template('hello ${ user.toUpperCase() } !');
compiled({ 'user': 'fred' });
最佳答案
格式化具有返回字符串的内联 Javascript:
hello <%= user.toUpperCase() %>
请注意 =
<%
之后
您还可以运行一段代码,而不必输出任何内容(尽管在本例中我在循环内执行)
<%
for (var i = 0;i < 10;i++){
%>
Hello user # <%= i %>
Welcome.
<% } %>
关于javascript - 模板内的 Lodash 调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39301941/