【问题标题】:Nested Each with Inner Value as key for Outer Object: Handlebars嵌套每个以内部值作为外部对象的键:Handlebars
【发布时间】:2017-03-08 05:44:32
【问题描述】:

我正在帮助使用多列表。在帮助器中,您可以指定要显示的对象列以及嵌套的每个循环,它应该都可以工作。我有我需要的值,但我无法让把手使用内部字符串值作为外部值的键。

我有一个几乎可以使用的PLNKR here with all the code in it.,您可以随意使用它。

它几乎可以工作..

我遇到问题的代码的简短部分是:

<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>

更具体地说:

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

我尝试过类似的方法:

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

我得到的最接近的返回是(将列名称赋予帮助器“名称”和“分数”):

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

提前感谢您提供解决或解决此问题的任何想法。

【问题讨论】:

    标签: javascript handlebars.js


    【解决方案1】:

    终于明白了!

    {{lookup ../this this}}
    

    【讨论】:

      猜你喜欢
      • 2018-09-26
      • 2019-12-16
      • 2021-12-26
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      • 2015-02-20
      相关资源
      最近更新 更多