代码之家  ›  专栏  ›  技术社区  ›  peirix

在jQuery tmpl中使用“if”

  •  11
  • peirix  · 技术社区  · 14 年前

    if jQuery tmpl模板中的句子?

    <script id="template" type="text/html">
        <h1>${someVar}</h1>
        if (${intro}!="")
            <small>${intro}</small>
        endif
        <p>${restOfVariables}</p>
    </script>
    

    现在,这只会把if写成文本,那么有什么方法可以这样做吗?或者我需要创建两个不同的模板并在调用模板之前签入js?

    1 回复  |  直到 14 年前
        1
  •  21
  •   sje397    10 年前

    根据 these docs

    <script id="template" type="text/html">
        <h1>${someVar}</h1>
        {{if intro != ""}}
            <small>${intro}</small>
        {{/if}}
        <p>${restOfVariables}</p>
    </script>