javascript - 在车把中,如何知道我是否在最后一次出现父数组
问题描述
我在车把项目中遇到了一个小问题。我正在使用一组嵌套数组,如下所示:
[
[
[
{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}}
任何人都知道如何在数组中“返回”以知道,例如,如果我在父数组的最后一个元素上?
解决方案
推荐阅读
- html - CSS:文本随机显示为斜体,以及什么都没有改变
- javascript - 如何从 html 中将参数传递给函数以做出反应?
- swift - 线程 1:异常:“从错误线程访问的领域。”
- html - html 元素只占屏幕的上半部分
- ansible - 使用 ansible assemble 清理碎片
- node.js - Mongoose:子文档不会在父文档更新时更新
- android - 在使用cordova、电容器和vuejs构建的android应用程序上只获取音频而不是视频
- gnu-assembler - 使用 GNU 程序集的主引导记录:平面二进制输出中的额外字节
- pandas - str vs Timestamp 类型索引和“loc”结果类型
- reddit - 渲染默认展开的嵌入