Javascript 下划线js-未捕获的语法错误:如果
我使用胡须插值:Javascript 下划线js-未捕获的语法错误:如果,javascript,underscore.js,underscore.js-templating,Javascript,Underscore.js,Underscore.js Templating,我使用胡须插值: _.templateSettings = { interpolate: /\{\{(.+?)\}\}/g }; 对于这段代码,我得到一个错误:uncaughtsyntaxerror:uncontractedtokenif <div class="d-none flex-container tip-container bg-white mt-5" data-ajax-template-empty-tip> <d
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g
};
对于这段代码,我得到一个错误:uncaughtsyntaxerror:uncontractedtokenif
<div class="d-none flex-container tip-container bg-white mt-5" data-ajax-template-empty-tip>
<div class="tip-header border border-bottom-0 d-flex flex-row p-2">
<div class="align-self-center mr-2">
<a href="./{{countryName}}" target="_blank">
<img class="d-block" alt="" src="/images/flags/{{countryId}}.png">
</a>
</div>
{{if (typeof(cityName) !== "undefined") { }}
<i class="fas fa-arrow-left align-self-center mr-2"></i>
<div class="align-self-center mr-2">
<a class="badge badge-primary" role="button" href="/city/{{cityName}}" target="_blank">
<span>{{cityName}}</span>
</a>
</div>
{{}}}
</div>
</div>
{{if(typeof(cityName)!=“未定义”){}
{{}}}
如果没有if语句,它工作得很好,但是有了它就不工作了,你知道怎么了吗?我在网上查看了每个问题,但都没有弄明白,我甚至删除了插值,并使用默认值在if之前尝试一个空格,如下所示:
{{ if (typeof(cityName) !== "undefined") { }}
我必须添加此设置才能正常工作:
_.templateSettings = {
evaluate: /\{\{(.+?)\}\}/g,
interpolate: /\{\{=(.+?)\}\}/g,
escape: /\{\{-(.+?)\}\}/g
};
我想这是因为
..templateSettings
你有{{}}语法的正确设置吗?在regex101.com上试用过,看起来不错。如果,您以前是否尝试过spac?