Tagi iteracji

Uwaga

12 października 2022 r. funkcja Portale usługi Power Apps została przekształcona w usługę Power Pages. Więcej informacji: Usługa Microsoft Power Pages jest teraz ogólnie dostępna (blog)
Wkrótce zmigrujemy i scalimy dokumentację funkcji Portale usługi Power Apps z dokumentacją usługi Power Pages.

Tagi iteracji są używane do wielokrotnego uruchamiania/renderowania bloku kodu.

for

Wielokrotnie wykonuje blok kodu. Jest najczęściej używany do przechodzenia przez elementy w tablicy lub słowniku.

W ramach bloku tagu for dostępny jest obiekt forloop.

Kod

{% for child_page in page.children %}

<a href={{ child_page.url }}>{{ child_page.title }}</a>

{% endfor %}

Dane wyjściowe

<a href=/parent/child1/>Child 1</a>

<a href=/parent/child2/>Child 2</a>

<a href=/parent/child3/>Child 3</a>

Parametry

Te parametry for mogą być używane samodzielnie lub w połączeniu.

limit

Kończy działanie pętli po danej liczbie obiektów.

Kod

{% for child_page in page.children limit:2 %}

<a href={{ child_page.url }}>{{ child_page.title }}</a>

{% endfor %}

Wynik

<a href=/parent/child1/>Child 1</a>

<a href=/parent/child2/>Child 2</a>

offset

Uruchamia pętlę przy danym indeksie.

Kod

{% for child_page in page.children offset:1 %}

<a href={{ child_page.url }}>{{ child_page.title }}</a>

{% endfor %}

Wynik

<a href=/parent/child2/>Child 2</a>

<a href=/parent/child3/>Child 3</a>

range

Określa zakres liczb pętli.

Kod

{% assign n = 4 %}

{% for i in (2..n) %}

{{ i }}

{% endfor %}

{% for i in (10..14) %}

{{ i }}

{% endfor }}

Wynik

2 3 4

10 11 12 14

reversed

Przechodzi przez pętlę w odwrotnej kolejności, począwszy od ostatniego elementu.

Kod

{% for child_page in page.children reversed %}

<a href={{ child_page.url }}>{{ child_page.title }}</a>

{% endfor %}

Wynik

<a href=/parent/child3/>Child 3</a>

<a href=/parent/child2/>Child 2</a>

<a href=/parent/child1/>Child 1</a>

cycle

Wykonuje pętlę przez grupę ciągów i wyświetla je w kolejności, przez która przez nie przechodzono, jako przez parametry. Po każdym wywołaniu cyklu, następny ciąg, który został parametrem, stanowi wyjście.

Kod

{% for item in items %}

<div class={% cycle 'red', 'green', 'blue' %}> {{ item }} </div>

{% end %}

Wynik

<div class=red> Item one </div>

<div class=green> Item two </div>

<div class=blue> Item three </div>

<div class=red> Item four </div>

<div class=green> Item five</div>

tablerow

Generuje tabelę HTML. Musi być ograniczony przez otwierającym tagiem <table> i zamykającym tagiem </table> HTML.

W ramach bloku tagu tablerow dostępny jest tablerowloop.

Kod

<table>

{% tablerow child_page in page.children %}

{{ child_page.title }}

{% endtablerow %}

</table>

Wynik

<table>

<tr class=row1>

<td class=col1>

Child Page 1

</td>

<td class=col2>

Child Page 2

</td>

<td class=col3>

Child Page 3

</td>

<td class=col4>

Child Page 4

</td>

</tr>

</table>

Parametry

Te parametry tablerowcan mogą być używane samodzielnie lub w połączeniu.

Wynik

<table>

<tr class=row1>

<td class=col1>

Child Page 1

</td>

<td class=col2>

Child Page 2

</td>

</tr>

<tr class=row2>

<td class=col3>

Child Page 3

</td>

<td class=col4>

Child Page 4

</td>

</tr>

</table>

Kod

<table>

{% tablerow child_page in page.children cols:2 %}

{{ child_page.title }}

{% endtablerow %}

</table>

Decyduje o tym, ile wierszy powinna mieć wygenerowana tabela.

cols

limit

Kończy działanie pętli po danej liczbie obiektów.

Kod

<table>

{% tablerow child_page in page.children limit:2 %}

{{ child_page.title }}

{% endtablerow %}

</table>

Wynik

<table>

<tr class=row1>

<td class=col1>

Child Page 1

</td>

<td class=col2>

Child Page 2

</td>

</tr>

</table>

offset

Uruchamia pętlę przy danym indeksie.

Kod

<table>

{% tablerow child_page in page.children offset:2 %}

{{ child_page.title }}

{% endtablerow %}

</table>

Dane wyjściowe

<table>

<tr class=row1>

<td class=col1>

Child Page 3

</td>

<td class=col2>

Child Page 4

</td>

</tr>

</table>

range

Określa zakres liczb pętli.

Kod

<table>

{% tablerow i in (1..3) %}

{{ i }}

{% endtablerow %}

</table>

Zobacz także

Tagi Przepływ sterowania Tagi zmienne Tagi szablonów Tagi encji Dataverse

Uwaga

Czy możesz poinformować nas o preferencjach dotyczących języka dokumentacji? Wypełnij krótką ankietę. (zauważ, że ta ankieta jest po angielsku)

Ankieta zajmie około siedmiu minut. Nie są zbierane żadne dane osobowe (oświadczenie o ochronie prywatności).