【问题标题】:unserscore,use "{{","}}" as interpolated symbol,i got an exception下划线,使用 "{{","}}" 作为插值符号,我遇到了异常
【发布时间】:2016-04-01 06:14:02
【问题描述】:

我怎样才能让它工作?
下划线 1.8
例外:
语法错误:预期的表达式,得到 ')'
任何帮助将不胜感激!

{{_.each(data,function(item){}}
<tr>
    <td>{{item.name}}</td>
    <td>{{item.gender}}</td>
    <td>{{item.age}}</td>
</tr>
 {{});}}

克服了一些麻烦,代码成功了

_.templateSettings = {
      interpolate: /\{\{=(.+?)\}\}/g,
      evaluate: /\{\{(.+?)\}\}/g,
    };

模板

{{_.each(data,function(item){}}
<tr>
    <td>{{=item.name}}</td>
    <td>{{=item.gender}}</td>
    <td>{{=item.age}}</td>
</tr>
{{})}}

引用each loop in underscore.js template

【问题讨论】:

    标签: javascript templates underscore.js


    【解决方案1】:

    根据guidelines 模板设置应为此更新。如果您可以与代码笔示例共享代码,因为您发布的代码没有多大意义。

    _.templateSettings = {
      interpolate: /\{\{(.+?)\}\}/g
    };
    
    var template = _.template("Hello {{ name }}!");
    template({name: "Mustache"});
    => "Hello Mustache!"
    

    【讨论】:

    猜你喜欢
    • 2020-08-17
    • 2021-02-15
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多