【问题标题】:handlebars outside scope array access范围数组访问之外的车把
【发布时间】:2018-02-14 04:55:15
【问题描述】:

我在 Pyramid 中使用车把。 我正在声明数组:

var profils = [
   "Profil 0",
   "Profil 1",
   "Profil 2',
   ];

在车把脚本中:

<script id="referents-list-template" type="text/x-handlebars-template">
    {{#each users as |user|}}
        <tr>
            ....
            <td>
                <select name="Profil-{{user.id}}" id="Profil-{{user.id}}" data-id="{{user.id}}">
                    {{#each ../../profils as |profil|}}
                        <option value="{{profil.id}}">{{profil.name}}</option>
                    {{/each}}
                </select>
            </td>
        </tr>
    {{/each}}

但是../../profils 不指向profils 数组。 我浏览了几篇关于这个问题的帖子,并认为../ 可以访问父元素,但在我的情况下它没有。

【问题讨论】:

  • 请在问题中添加整个data 对象。

标签: scope handlebars.js pyramid


【解决方案1】:

../ 不会指向父数组,而是指向对象的root。 因此,我相信您可以使用 ../profils 获得所需的输出。

【讨论】:

    【解决方案2】:

    感谢您的贡献。 我最终以稍微不同的方式实现了它。 我通过一个函数加载车把脚本。 该函数在参数中采用 profils 数组。 这样做,我在把手脚本中访问 profils 数组就没有问题了。

    【讨论】:

      猜你喜欢
      • 2015-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多