獲得HTML結果我在我的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?");
的alerts()
在那裏純粹是爲了調試的目的。
section_template
正確填入,我準備
template
具有作爲它的價值,所以我假定編譯順利過的模板。
「是啊!」並且上下文的標題正確顯示。但是,執行template(context);
時似乎出現了錯誤。 「什麼?」警告永遠不會被提出,因此HTML內容永遠不會被設置(稍後在程序中)。後來在程序中,我使用final_section_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>
控制檯中是否有錯誤? –
另外我發現,'console.log'(除非你在IE中)比嘗試調試時中斷警報更容易處理。一探究竟! – tkone
@RyanLynch是的,你是對的。錯誤是「Uncaught TypeError:無法調用未定義的方法匹配」。不知道這意味着什麼... tkone - 是的。我想我會從現在開始使用,而不是alert() – user109187