I have published all my code as a runnable that uses express for loading static content未知模板對象錯誤2.0運行
我已預編譯此車把模板:
<img src="{{coverImage}}"/>
<ul>
<li>{{title}}</li>
<li>{{author}}</li>
<li>{{releaseDate}}</li>
<li>{{keywords}}</li>
</ul>
刪除
我已獲得此功能:
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['bookTemplate'] = template(function (Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
var buffer = "", stack1, helper, functionType="function", escapeExpression=this.escapeExpression;
buffer += "<img src=\"";
if (helper = helpers.coverImage) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.coverImage); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "\"/>\r\n <ul>\r\n <li>";
if (helper = helpers.title) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.title); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n <li>";
if (helper = helpers.author) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.author); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n <li>";
if (helper = helpers.releaseDate) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.releaseDate); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n <li>";
if (helper = helpers.keywords) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.keywords); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n </ul>\r\n<button class=\"delete\">Delete</button>";
return buffer;
});
})();
我有添加了這樣的腳本:
<script src="js/lib/handlebars.runtime-v2.0.0.js"></script>
<script src="js/templates.js"></script>
我在Chrome Dev Tools
看到這兩個腳本加載。
然而,當我使用它是這樣的:
//inside a Backbone view
template:Handlebars.templates.bookTemplate
我得到這個錯誤:
Uncaught Error: Unknown template object: function handlebars.runtime-v2.0.0.js:455template handlebars.runtime-v2.0.0.js:455hb.template handlebars.runtime-v2.0.0.js:644(anonymous function) templates.js:3(anonymous function)
我得到線455這個錯誤在handlebars runtime @2.0.0
在功能template
,在做一個小調試我發現templateSpec
是一個函數,但templateSpec.main
是undefined
:
//this function makes a call to templates['bookTemplate'] = template(function (Handlebars,depth0,helpers,partials,data) {...} in the `bookTemplate.js`
function template(templateSpec, env) {
/* istanbul ignore next */
if (!env) {
throw new Exception("No environment passed to template");
}
//error occurs here:
if (!templateSpec || !templateSpec.main) {
throw new Exception('Unkn own template object: ' + typeof templateSpec);
}
...
此外,我發現Handlebars.templates是一個空對象。
這是怎麼回事?
任何在[here](https://github.com/leshill/handlebars_assets/issues/110)聽起來很熟悉?其他任何[Google點擊](https://www.google.ca/#q=handlebars+Uncaught+Error%3A+Unknown+template+object)如何? – 2014-09-29 23:39:57
@ muistooshort我在Chrome中禁用瀏覽器緩存,谷歌點擊太複雜,我做的很簡單,我預編譯一個句柄模板,並使用它與運行時庫,沒有服務器,使用'file://',更新顯示錯誤位置的帖子 – vamsiampolu 2014-09-30 01:51:16
@ muistooshort'templateSpec.main'是'undefined' – vamsiampolu 2014-09-30 02:02:01