Javascript Underline.js模板:未呈现模板变量

Javascript Underline.js模板:未呈现模板变量,javascript,jquery,templates,underscore.js,single-page-application,Javascript,Jquery,Templates,Underscore.js,Single Page Application,我刚刚开始使用jQuery和underline.js了解使用JavaScript开发单页应用程序的基础知识。在进入任何客户端MVC框架之前,我想了解一些更基本的东西,比如模板插入 我的问题:当通过u.Template()呈现HTML时,不会计算模板变量。HTML: <body> <script id="app-view-1" type="text/template"> <div id="app-view-1-container" class="a

我刚刚开始使用jQuery和underline.js了解使用JavaScript开发单页应用程序的基础知识。在进入任何客户端MVC框架之前,我想了解一些更基本的东西,比如模板插入

我的问题:当通过u.Template()呈现HTML时,不会计算模板变量。HTML:

<body>
    <script id="app-view-1" type="text/template">
      <div id="app-view-1-container" class="app-workbench-container active-panel">
        <h2><%= title =></h2>
        <ul class="choice-list">
          <li><a class="" id="" href="#" data-choice="choice 1"></a></li>
          <li><a class="" id="" href="#" data-choice="choice 2"></a></li>
        </ul>
      </div>
    </script>

    <script id="app-view-2" type="text/template">
      <div id="app-view-2-container" class="app-workbench-container active-panel">
        <h2><%= title =></h2>
        <form id="" class="input-panel active-panel" action="#">
          <input type="text" id="input-field-1" class="app-control">
          <input type="radio" id="radio-button-1" class="app-control" value="value-1">Value 1
          <input type="submit" id="submit-button-1" class="app-control">
        </form>
      </div>
    </script>

    <header id="app-header">
      <h1>Single Page App (SPA) Test</h1>
      <nav id="main-menu-panel">
        <ul id="main-menu">
          <li class="main-menu-item"><a id="view-1" class="" data-target="app-view-1" href="#">View 1</a></li>
          <li class="main-menu-item"><a id="view-2" class="" data-target="app-view-2" href="#">View 2</a></li>
          <li class="main-menu-item"><a id="view-3" class="" data-target="app-view-3" href="#">View 3</a></li>
        </ul>
      </nav>
    </header>

    <main id="app-body">
      <p class="active-panel">Different app partials come here...</p>
    </main>

    <footer></footer>

    <script src="js/vendors/jquery/jquery-1.10.2.min.js"></script>
    <script src="js/vendors/node_modules/underscore/underscore-min.js"></script>
    <script src="js/app.js"></script>

  </body>

但是,“”在呈现的输出中显示为文字字符串,而实际的标题(应该在partial()函数中指定)不会显示。这里怎么了?非常感谢您的帮助。

您的模板错误。您正在使用
,而它应该是

根据中的信息,他们提供了以下示例

var compiled = _.template("hello: <%= name %>");
compiled({name: 'moe'}); // returns "hello: moe"
var compiled=ux0.template(“hello:”);
已编译({name:'moe'});//返回“你好:moe”
支持的下划线.js模板标记包括:

  • 用于脚本执行
  • 插入变量(打印)
  • 插入变量并对其进行HTML转义
编辑

我用过。将来,请提供这样一个例子,它会让每个人都更轻松。:)

var compiled = _.template("hello: <%= name %>");
compiled({name: 'moe'}); // returns "hello: moe"