【问题标题】:Ember/ Liquid - Each statement multi-dimentional arrayEmber/ Liquid - 每个语句的多维数组
【发布时间】:2016-02-24 23:15:48
【问题描述】:

我在使用 ember #each 语句时遇到了一些困难。我想从下面的 HTML 代码中的多维数组中打印第 [0] 和第 [1] 位置值。即,我想在单独的 HTML 代码块中打印值 Product X、Y、Z 和 GROUP A、B、C。 this.get(0) 不起作用。

var uiTags = [
   ['**Product X**','GROUPA', '350'],
   ['**Product Y**','GROUPB', '150'],
   ['**Product Z**','GROUPC', '575']
];

HTML 代码:

<ul class="list-group list-group-menu">
  {% raw %}{{#each uiTags}}{% endraw %}

   <!-- Print product name start (This block should print the product name) -->
    <li class="list-group-item"><a href="#">          
      <div class="checkbox checkbox-primary">
        <input type="checkbox" checked id="map-filter-{% raw %}{{ @index }}{% endraw %}" value="{% raw %}{{ this }}{% endraw %}"/>
        <label for="map-filter-{% raw %}{{ @index }}{% endraw %}">{% raw %}{{ this }}{% endraw %}</label>
      </div></a>
    </li>
   <!-- Print product name end-->

   <!-- Print group name start (This block should print the group name) -->
    <li class="list-group-item"><a href="#">          
      <div class="checkbox checkbox-primary">
        <input type="checkbox" checked id="map-filter-{% raw %}{{ @index }}{% endraw %}" value="{% raw %}{{ this }}{% endraw %}"/>
        <label for="map-filter-{% raw %}{{ @index }}{% endraw %}">{% raw %}{{ this }}{% endraw %}</label>
      </div></a>
    </li>
   <!-- Print group name end-->


  {% raw %}{{/each}}{% endraw %}
</ul>

【问题讨论】:

    标签: arrays node.js ember.js liquid swig-template


    【解决方案1】:

    You can use the get helper to access a specific index.:

    <ul>
      {{#each model as |row|}}
        <li>
          <ul>
            <li>{{get row "0"}}</li>
            <li>{{get row "1"}}</li>
          </ul>
        </li>
      {{/each}}
    </ul>
    

    And an ember twiddle with it.

    【讨论】:

      猜你喜欢
      • 2019-06-02
      • 1970-01-01
      • 2011-07-18
      • 1970-01-01
      • 2016-10-18
      • 2019-03-20
      • 2014-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多