Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.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 未呈现把手模板-可以在Firefox Inspector中查看HTML_Javascript_Jquery_Html_Handlebars.js - Fatal编程技术网

Javascript 未呈现把手模板-可以在Firefox Inspector中查看HTML

Javascript 未呈现把手模板-可以在Firefox Inspector中查看HTML,javascript,jquery,html,handlebars.js,Javascript,Jquery,Html,Handlebars.js,我在一个外部文件(user listing template.html)中有一个Handlebar模板,我通过JQuery Ajax调用动态加载该模板以检索该文件,通过handlebar.compile进行编译,然后显示在div中。请参见下面的示例代码: 模板文件: <script id="user-listing-template" type="text/x-handlebars-template"> <h2 class="ui header">User Maint

我在一个外部文件(user listing template.html)中有一个Handlebar模板,我通过JQuery Ajax调用动态加载该模板以检索该文件,通过handlebar.compile进行编译,然后显示在div中。请参见下面的示例代码:

模板文件:

<script id="user-listing-template" type="text/x-handlebars-template">
  <h2 class="ui header">User Maintenance</h2>
  <hr>
  <h4 class="text-align-left">Total Users: </h4>
  <br><br>
</script>
在index.html中,我有一个div,希望在其中看到模板:

<div id="app"></div>

但是,当我运行此应用程序时,不会呈现模板。我可以在Firefox开发工具的Inspector中看到模板的HTML代码:

所有的控制台.Log.()语句都显示了有效的HTML代码,但是它不会显示,我只看到空白页。控制台输出如下所示:

很明显,我做错了什么,只是不确定是什么——除了渲染部分之外,一切似乎都正常


非常感谢您的帮助。我对车把还比较陌生,我只是在尝试一个概念验证应用。

根据官方网站。您只需编译模板而不生成html

template = Handlebars.compile(source);
var html = template(yourdata);     // yourdata is the object rendered to your template
$('#app').html(html);   // can not be template variable, variable html is final html content

检索模板文件时,将使用
标记对其进行封装。车把只需要内容。因此(正如您在Firefox inspector中看到的),编译后的输出是不可显示的HTML,因为它仍然在原始的
脚本
标记中

当您将数据分配给
source
变量时,需要从数据中提取HTML

success: function( data ) {
    source = $( data ).html();
    ...
success: function( data ) {
    source = $( data ).html();
    ...