首页 > 解决方案 > 在车把中,如何知道我是否在最后一次出现父数组

问题描述

我在车把项目中遇到了一个小问题。我正在使用一组嵌套数组,如下所示:

[
   [
      [
         {Object: "Object1"},
         {Object: "Object2"}
      ],
      [
         {Object: "Object3"},
         {Object: "Object4"}
      ]
   ],
   [
      [
         {Object: "Object5"},
         {Object: "Object6"}
      ],
      [
         {Object: "Object7"},
         {Object: "Object8"}
      ]
   ],
   [
      [
         {Object: "Object5"},
         {Object: "Object6"}
      ],
      [
         {Object: "Object7"},
         {Object: "Object8"}
      ]
   ]
]

我知道我可以使用 @first 和 @last 布尔值来知道我是否位于当前迭代数组的最后一个元素。

{{#each foo}}
    <div class='{{#if @first}}first foo{{/if}}
                {{#if @last}} last foo{{/if}}'>
      {{@key}} - {{@index}}
    </div>
{{/each}}

但是如果我想知道我是否在数组的最后一个元素上呢?

{{#each fooParent}}
   {{#each foo}}
       <div class='{{#if @first}}first foo not fooparent{{/if}}
                   {{#if @last}} last foo not fooparent{{/if}}'> <!-- How can I know here 
                                                                      that I am on the 
                                                                      last item of the 
                                                                     fooParent array? --> 
         {{@key}} - {{@index}}
       </div>
   {{/each}}
{{/each}}

任何人都知道如何在数组中“返回”以知道,例如,如果我在父数组的最后一个元素上?

标签: javascripttypescripthandlebars.js

解决方案


推荐阅读