【发布时间】:2013-11-13 15:08:43
【问题描述】:
由于某种原因,我无法在我的模板中调用我的助手。它会抛出一个错误,说我的助手未定义。
我有以下代码:
<script type="text/x-handlebars" id="catalog">
<div class="col-md-10">
<ul class="list-group">
{{#each catalog.catalog_categories}}
{{categoryHelper this}} // This works !!!
{{/each}}
</ul>
</div>
</script>
<script id="categories-template" data-template-name='test' type="text/x-handlebars-template">
<a data-toggle="collapse" href=".collapse{{ category.category_id }}" data-target=".child{{ category.category_id }}">
<li class="list-group-item">
{{ category.category_name_fr_sh }} // French name of category
</li>
</a>
{{#if category.category_children}}
{{#each category.category_children}}
{{categoryHelper this}} // This throw error saying that the helper is undefined
{{/each}}
{{/if}}
</script>
//app.js
Ember.Handlebars.helper('categoryHelper', function(category) {
var template = Handlebars.compile($('script#categories-template').html());
return new Handlebars.SafeString(template({category: category}));
});
编辑: 这是一个jsfiddle http://jsfiddle.net/CycS8/
【问题讨论】:
-
@RoyDaniels 我用我的 jsfiddle 的链接更新了我的答案。感谢您的帮助