Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 下划线不';t替换变量_Javascript_Templates_Underscore.js - Fatal编程技术网

Javascript 下划线不';t替换变量

Javascript 下划线不';t替换变量,javascript,templates,underscore.js,Javascript,Templates,Underscore.js,我在js中有以下行: terminalsListHtml += this.compiled(_.extend(this.terminals[i], {clazz: 'all'}, obj)); 我调试以下代码: 尝试求值.extend(this.terminals[i],{clazz:'all'},obj): 看起来不错 但是试着评估一下 this.compiled(_.extend(this.terminals[i], {clazz: 'all'}, obj)); 这对我来说不是预期

我在js中有以下行:

 terminalsListHtml += this.compiled(_.extend(this.terminals[i], {clazz: 'all'}, obj));
我调试以下代码:

尝试求值
.extend(this.terminals[i],{clazz:'all'},obj)

看起来不错

但是试着评估一下

this.compiled(_.extend(this.terminals[i], {clazz: 'all'}, obj));

这对我来说不是预期的结果

请帮助修复描述的问题

附言


它在移动后工作

<script type="text/javascript">
    _.templateSettings = {
        interpolate: /\{\{(.+?)\}\}/gim,
        evaluate: /\{\{(.+?)\}\}/gim,
        escape: /\{\{\-(.+?)\}\}/gim
    };
</script>

_.templateSettings={
插值:/\{(.+?)\}}/gim,
求值:/\{(.+?)\}\}/gim,
转义:/\{-(.+?)\}}/gim
};

默认情况下,下划线模板在文件开头使用ERB语法,例如
。您是否指定要使用mustache.js样式
{{foobar}}
模板?有关如何启用此功能的信息,请参阅。您是否已更新
.templateSettings
以使用把手语法?@mu太短,您是否同意此语法?.templateSettings={插值:/\{(.+?)\}/gim,求值:/\{(.+?)\}/gim,转义:/\{-(.+?)\}/gim@穆太短了,你的评论帮助了我。
_.templateSettings = {
        interpolate: /\{\{(.+?)\}\}/gim,
        evaluate: /\{\{(.+?)\}\}/gim,
        escape: /\{\{\-(.+?)\}\}/gim
    };
<script type="text/javascript">
    _.templateSettings = {
        interpolate: /\{\{(.+?)\}\}/gim,
        evaluate: /\{\{(.+?)\}\}/gim,
        escape: /\{\{\-(.+?)\}\}/gim
    };
</script>