2016-11-08 39 views
1

我试着去渲染基于变量名的谐音,根据these docs正确的方法是:使用var作为部分名称?

Subexpressions do not resolve variables so whichPartial must be a function. If a simple variable has the partial name, it's possible to resolve it via the lookup helper.

{{> (lookup . 'myVariable') }} 

所以我曾尝试:

{{#each index.types}} 
    {{> (lookup . this.type) }} 
{{/each}} 

但我得到的错误:

Error: The partial undefined could not be found 

我也在循环中输出以下内容:

{{this.type}} 

正在读取正确的部分字符串。

回答

0

我有使用{{this}}作为部分名称的类似问题。我设法通过局部块来解决这个问题如下:

{{#each this as |tab| }} 
     {{> (tab)}} 
{{/each}} 

你的情况,你可以尝试:

{{#each index.types as |item| }} 
    {{> (item.type)}} 
{{/each}} 
相关问题