Why can't I call my Handlebars partial inside #each?
While refactoring some code I got this problem: When applying a Handlebars template that uses a partial, it complains about You must pass a string or Handlebars AST to Handlebars.compile. You passed function ...
You must pass a string or Handlebars AST to Handlebars.compile. You passed function ...
. The function is this:
function (context, options) {
options = options || {};
var namespace = options.partial ? options : env,
helpers,
partials;
if (!options.partial) {
helpers = options.helpers;
partials = options.partials;
}
var result = templateSpec.call(
container,
namespace, context,
helpers,
partials,
options.data);
if (!options.partial) {
checkRevision(container.compilerInfo);
}
return result;
}
What I did:
A partial is used to iterate over a list (called members) to build a ul
of checkboxes. I found out I needed to make a list of lists and put the call to the partial inside an #each
and updated the template input.
I have this:
Template:
...
{{#each hierarchy.levels}}
<ul>
{{> mypartial}}
</ul>
{{/each}}
Partial (simplified):
{{#each members}}
<li>{{this.id}}</li>
{{/each}}
I've checked that each hierarchy.levels
in my data structure has a members
list.
If I replace the #each
in my template with #with hierarchy.levels.[0]
(for instance) it works but it won't work when iterating over levels
.
链接地址: http://www.djcxy.com/p/61590.html