嗨,我有一个淘汰赛的情况,我需要遍历一个数组并生成一些这样的标记:
<section data-bind="foreach: category().questions">
<article>
<!-- ko if: hasGrade-->
<header data-bind="text: description"></header>
<ul>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">6</a></li>
<li><a href="#">7</a></li>
<li><a href="#">8</a></li>
<li><a href="#">9</a></li>
<li><a href="#">10</a></li>
</ul>
<!-- /ko -->
<!-- ko if: hasMemo-->
<header data-bind="text: memoTitle"></header>
<textarea>safa</textarea>
<!-- /ko -->
</article>
</section>
现在的问题是我必须生成一个类似这样的结构:
<section>
<article></article>
<article></article>
<article></article>
<article></article>
<article></article>
</section>
<section>
<article></article>
<article></article>
<article></article>
<article></article>
<article></article>
</section>
<section>
<article></article>
<article></article>
<article></article>
<article></article>
<article></article>
</section>
例如,如果我在数组中有 15 个问题,我将不得不生成 3 个部分,其中我有 5 个问题代表一个问题的文章。这只是一个示例,我也可以有 20 个项目左右。
我怎样才能通过淘汰赛实现这一目标?
**Edit**
categories: [{
categoryId: 1,
title: "Docent",
hasMemo: true,
memoIsMandatory: false,
memoTitle: "Docent Opmerkingen",
questions: [{
questionId: 11,
description: "De docent is goed voorbereid",
hasGrade: false,
hasMemo: true,
showOnlyMemo: true,
memoTitle: "De docent is goed voorbereid"
}, {
questionId: 12,
description: "De docent heeft kennis van zaken",
hasGrade: true,
hasMemo: false,
showOnlyMemo: false,
memoTitle: "De docent heeft kennis van zaken"
}, {
questionId: 13,
description: "De docent kan de onderwerpen boeiend uitleggen",
hasGrade: true,
hasMemo: false,
showOnlyMemo: false,
memoTitle: "De docent kan de onderwerpen boeiend uitleggen"
}, {
questionId: 14,
description: "De docent gaat goed in op de vragen uit de groep",
hasGrade: true,
hasMemo: false,
showOnlyMemo: false,
memoTitle: "De docent gaat goed in op de vragen uit de groep"
}, {
questionId: 15,
description: "De docent stimuleert de groep tot actieve deelname",
hasGrade: true,
hasMemo: false,
showOnlyMemo: false,
memoTitle: "De docent stimuleert de groep tot actieve deelname"
}, {
questionId: 16,
description: "De docent voegt inhoudelijk iets toe aan het studiemateriaal",
hasGrade: true,
hasMemo: false,
showOnlyMemo: false,
memoTitle: "De docent voegt inhoudelijk iets toe aan het studiemateriaal"
}, {
questionId: 17,
description: "De docent is praktijkgericht",
hasGrade: true,
hasMemo: false,
showOnlyMemo: false,
memoTitle: "De docent is praktijkgericht"
}, {
questionId: 18,
description: "Totaal oordeel over de docent",
hasGrade: true,
hasMemo: false,
showOnlyMemo: false,
memoTitle: "Totaal oordeel over de docent"
}]
}, {
categoryId: 7,
title: "Opbouw programma en studiemateriaal",
hasMemo: true,
memoIsMandatory: false,
memoTitle: "Opbouw programma en studiemateriaal Opmerkingen",
questions: [{
questionId: 54,
description: "Het studieprogramma is duidelijk opgebouwd",
hasGrade: true,
hasMemo: false,
showOnlyMemo: false,
memoTitle: "Het studieprogramma is duidelijk opgebouwd"
}, {
questionId: 55,
description: "Het studiemateriaal is compleet, goed leesbaar en praktijkgericht",
hasGrade: true,
hasMemo: false,
showOnlyMemo: false,
memoTitle: "Het studiemateriaal is compleet, goed leesbaar en praktijkgericht"
}]
}],
请注意我不允许修改这个 observable 的结构
第二次编辑
<div data-bind="foreach: category().questions">
<!-- ko if: ($index % 5) === 0 -->
<section >
<!-- /ko -->
<article>
<!-- ko if: hasGrade-->
<header data-bind="text: description"></header>
<ul>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">6</a></li>
<li><a href="#">7</a></li>
<li><a href="#">8</a></li>
<li><a href="#">9</a></li>
<li><a href="#">10</a></li>
</ul>
<!-- /ko -->
<!-- ko if: hasMemo-->
<header data-bind="text: memoTitle"></header>
<textarea></textarea>
<!-- /ko -->
</article>
<!-- ko if: ($index % 5) === 0 -->
</section>
<!-- /ko -->
</div>
我尝试添加此表达式:但由于某种原因它不再显示任何内容。如果我删除它,我会得到数据但它没有显示我想要它是不是我没有写这个表达式对吗?
<!-- ko if: ($index % 5) === 0 -->