下划线js-未捕获的SyntaxError:如果出现意外令牌

我使用小胡子插值法:


    _.templateSettings = {

        interpolate: /\{\{(.+?)\}\}/g

    };

对于此代码,我得到以下错误:Uncaught SyntaxError:如果出现意外令牌


<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语句,它将很好地工作,但是如果不起作用,就知道出了什么问题吗?我在网上查看了每个问题,无法解决,我什至删除了插值,并使用默认的<%,但不是。


jeck猫
浏览 164回答 2
2回答

翻过高山走不出你

我必须添加此设置才能使其正常工作:&nbsp; &nbsp;_.templateSettings = {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; evaluate: /\{\{(.+?)\}\}/g,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; interpolate: /\{\{=(.+?)\}\}/g,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; escape: /\{\{-(.+?)\}\}/g&nbsp; &nbsp; &nbsp; &nbsp; };

慕慕森

在if之前尝试一个空格,如下所示:{{&nbsp;if&nbsp;(typeof(cityName)&nbsp;!==&nbsp;"undefined")&nbsp;{&nbsp;}}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript