0
我想使用Ajax來加載包含多個Handlerbars模板的html頁面。我有一個調用,比如:從Ajax調用多個Handlerbars JS模板調用
$.ajax({
url: optList.baseURL + "/HandlerBarTemplate.html",
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: true,
async: false,
success: function (data) {
source = data;
$('#hbList').html(source);
},
error: function (xhr, status, error) {
alert(error);
}
});
我在HTML模板是這樣的:
<script id="item-panel-template1" type="text/x-handlebars-template">
<script id="item-panel-template2" type="text/x-handlebars-template">
...
我見過有一個文件中的個人模板的例子,但還沒有看到任何一個地方文件包含多個模板。
這個例子看起來像你要求的? http://berzniz.com/post/24743062344/handling-handlebars-js-like-a-pro –
除非這些模板是動態創建的,爲什麼不預先編譯並加載它們? – pdoherty926
凱西該帖子要求每個模板都在我想要避免的單個文件中。 – keitn