在 total.js 中是否可以将值赋给变量或 save/use 在 HTML 中嵌套的 @{foreach...} 内联的 @{foreach...} 的索引?

In total.js is it possible to assign value to variables or save/use the index of a @{foreach...} inside a nested @{foreach...} inline in the HTML?

例如,是否可以 define/use 一个 "item_index" 类似的例子:

<div>
 @{foreach item in list}
  <p>@{item.title}:<p>
  @{foreach content in item.contents}
   <p>@{content.name} is the @{index}th content of @{item.title}, and the @{item_index}th item in the list</p>
  @{end}
 @{end}
</div>

是否可以在进入嵌套循环之前赋值,如@{item_index = index}?

您可以使用 R(存储库的缩写)来存储额外的数据。 这有效:

@{foreach m in [1, 2, 3, 4]}
    @{R.index = index}
    @{foreach m2 in [10, 20, 30, 40]}
        <div>@{m2}, index: @{R.index}, index2: @{index}</div>
    @{end}
@{end}

输出:

<div>10, index: 0, index2: 0</div>
<div>20, index: 0, index2: 1</div>
<div>30, index: 0, index2: 2</div>
<div>40, index: 0, index2: 3</div>
<div>10, index: 1, index2: 0</div>
<div>20, index: 1, index2: 1</div>
<div>30, index: 1, index2: 2</div>
<div>40, index: 1, index2: 3</div>
<div>10, index: 2, index2: 0</div>
<div>20, index: 2, index2: 1</div>
<div>30, index: 2, index2: 2</div>
<div>40, index: 2, index2: 3</div>
<div>10, index: 3, index2: 0</div>
<div>20, index: 3, index2: 1</div>
<div>30, index: 3, index2: 2</div>
<div>40, index: 3, index2: 3</div>