简体   繁体   English

将内部值嵌套为每个外部对象的关键:车把

[英]Nested Each with Inner Value as key for Outer Object: Handlebars

I am making a help to use for multi-col tables. 我正在帮助使用多列表。 In the helper you specify which object columns you want to display and with nested each loops it should all work. 在帮助器中,指定要显示的对象列,并嵌套每个循环,所有这些列都应正常工作。 I have the values I need where I want them but I can't get handlebars to use the inner string value as a key for the outer value. 我在需要它们的地方有所需的值,但我无法使用把手将内部字符串值用作外部值的键。

I have an almost working PLNKR here with all the code in it. 这里几乎所有代码都可以正常工作的PLNKR。 which you can play around with. 您可以一起玩。

It almost works.. 差不多了。

The short part of the code where I'm having an issue is: 我遇到问题的一小段代码是:

<table>
 {{#items}}
  <tr >
    {{#each ../colNames}}
      <td>{{../this}}.{{this}}</td>
    {{/each}}
    <td>
      <input type="checkbox" 
        id="masterList{{@index}}"
        {{#if this.selected}}checked{{/if}}
        onchange="{{../checkAction}}({{@index}})"
      >
    </td>
  </tr>
 {{/items}}
</table>

Even more specifically: 更具体地说:

<td>{{../this}}.{{this}}</td>

I have tried things like: 我已经尝试过类似的事情:

<td>{{../this}}.[{{this}}]</td>
<td>{{../this}}.[this]}}</td>
<td>{{../this.this}}</td>
<td>{{../this.(this)}}</td>

The closest I get returns like (with column names given to the helper "name" and "score"): 我得到的最接近的返回值是这样的(将列名指定给助手“名称”和“分数”):

<td>[object Object].name</td>   
<td>[object Object].score</td>

Thanks in advance for any ideas to solve or work around this. 在此先感谢您提出解决或解决此问题的任何想法。

终于明白了!

{{lookup ../this this}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM