Javascript 无法通过使用上下文执行把手模板来获取HTML结果

Javascript 无法通过使用上下文执行把手模板来获取HTML结果,javascript,templates,handlebars.js,Javascript,Templates,Handlebars.js,我的javascript中有以下代码: var context = { "title": section_title }; var section_template = $("section-template").html(), template = Handlebars.compile(section_template); alert("yeah!"); alert(context.title); var fi

我的javascript中有以下代码:

    var context = {
        "title": section_title
    };

    var section_template = $("section-template").html(),
        template = Handlebars.compile(section_template);

    alert("yeah!");
    alert(context.title);
    var final_section_content = template(context);

    alert("WHat?");
警报()
仅用于调试目的

section\u模板
正确填充了我准备的模板

template
有一个函数作为其值,因此我认为编译也进行得很顺利

“yeah!”和上下文的标题显示正确。然而,
模板(上下文)似乎出了问题执行。“What?”警报从未发出,因此HTML内容从未设置(稍后在程序中)。在程序的后面,我使用
final\u section\u content
作为jQuery
before()
函数的值。但“什么?”本身并没有被执行。知道为什么吗

模板代码:

<script id="section-template" type="text/x-handlebars-template">
    <div class="row-fluid">
        <div class="span8 offset1">
            {{! This will contain the section requirements}}
            <div class="section-title">
                <span class="add-on">
                    <i class="icon-plus-sign"></i>
                </span>

                <h2>
                    {{title}}
                </h2>
                <i class="icon-list" data-placement="bottom" data-title="Create sub-section"></i>
                <i class="icon-pencil" data-placement="bottom" data-title="Edit section title"></i>
                <i class="icon-trash" data-placement="bottom" data-title="Delete section"></i>
                <div class="subsection">
                    {{! Dummy container for subsection}}
                </div>
            </div>
        </div>
        <div class="span2 offset1">
            {{! This will contain the total score for the section}}
        </div>
    </div>
</script>

{{!这将包含节要求}
{{title}}
{{!子节的虚拟容器}
{{!这将包含该部分的总分}

在使用
$(“#section template').html()查询包含模板代码的元素内容之前,请确保已加载该元素。
。有关更多详细信息,请参阅。

控制台中是否有错误?我还发现,
console.log
(除非您在IE中)比在尝试调试时中断警报更容易处理。看看@RyanLynch是的,你是对的。错误为“UncaughtTypeError:无法调用未定义的方法'match'。不知道这是什么意思。。。是的。我想我会从现在开始使用它,而不是alert()。你的模板是什么样子的?难道
$(“节模板”)
不应该是
$(“#节模板”)
?您看到的错误通常意味着您已经对@muistooshort执行了
handlebar.compile(null)
.a+1操作。