> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# arc:enum

> 迭代物件的屬性、分隔清單、值範圍或多值屬性的值，並對每個元素執行正文。

export const siteNameShort = "知行之橋";

arc:enum 關鍵字可以用於列舉物件中的屬性，分隔清單，數值範圍和多值屬性中的值。arc:enum 的主體會執行要迭代集合中的每個元素。

## 參數

* **item**：要對其屬性進行迭代的物件的名稱。
* **attr**：指定迭代哪些屬性的匹配運算式。例如，“arc:\*”。也可以使用該參數來迭代多值屬性的值。
* **prefix**：列舉物件基於的字首。
* **expand**：布林值，指定當遇到多值屬性時，arc:enum 如何執行。如果 expand 設定為 true，arc:enum 的主體會將屬性中的每個值都執行一次。如果為 false，所有值將會串聯在一個字串值裡，只執行單次迭代。預設情況下，arc:enum 不會展開所有值。
* **sep\[arator]**：如果 expand 參數為 false，則用來連線多值屬性值的分隔符號。除此之外，如果未定義清單分隔符號，則使用分隔符號對清單中的值進行標記。預設值為換行字元“\n”。
* **list**：要列舉的分隔值清單。例如，如果清單為 “violet，indigo，blue，green，yellow，orange，red” 且分隔符號為 “,”，那麼對每個顏色都將會執行 arc:enum 的範圍。
* **range**：以升序或降序列舉時字母或字元的範圍；例如，“a..z”，“Z..A”。

<Note>可以指定 **range** 參數或 **item** 參數，但不能同時指定兩者。屬性按字母順序列舉。</Note>

## 控制屬性

* **\_attr**: 被迭代的屬性名稱。當對多值屬性進行迭代時，屬性名稱將相同，只是會包含索引作為名稱的一部分。使用雜湊符號（#）將名稱和索引分隔開。例如，name#1，name#2等。
* **\_index**：屬性出現在物件中的索引或當前列舉元素在清單中的位置。
* **\_value**：被迭代的屬性的值。對於一個多值屬性，expand 和 separator 參數設定決定了 \_value 是對一個屬性值的引用還是對所有屬性值的引用。
* **\_count**：在一個屬性或一個清單中值的數量。
* **\_separator**：清單中用來分隔值的分隔符號。

## 範例

顯示物件名為“input”的屬性名稱和屬性值：

```xml theme={null}
<arc:set item="input" attr="Greeting" value="Hello" />
<arc:set item="input" attr="Goodbye" value="See ya" />
<arc:enum item="input">
  [_attr] is [_value]
  <br/>
</arc:enum> 
```

```
goodbye is See ya greeting is Hello
```

使用 arc:enum **list** 和 **separator** 參數列舉一個值的清單。例如，下面的程式碼列出了在 colors 屬性中指定的顏色：

```xml theme={null}
<arc:set attr="colors" value="violet, indigo, blue, green, yellow, orange, red"/>
<arc:enum list="[colors]" separator=",">
  [_value] 
</arc:enum>
```

要列舉一個範圍內的值，使用 **range** 參數，下面的程式碼列出了從 a 到 z，從 Z 到 A，以及從1到25的字元集：

```xml theme={null}
<arc:enum range="a..z">
  [_value] 
</arc:enum>
<arc:enum range="Z..A">
  [_value] 
</arc:enum>
<arc:enum range="1..25">
  [_value] 
</arc:enum>
```

要列舉一個多值元素的所有值，使用 **\_attr** 參數來指定多值屬性並且將 expand 設為 true：

```xml theme={null}
<arc:set attr="foo.email#1" value="joe@mycompany.com"/>
<arc:set attr="foo.email#2" value="john@mycompany.com"/>
<arc:enum attr="foo.email" expand="true">
    ([_index]) [_attr] -> [_value]
</arc:enum>
```

上面的範例最終輸出了以下的內容：

```
(1) email#1 -> joe@mycompany.com (2) email#2 -> john@mycompany.com
```

## 另請參閱

* [arc:break](./op-arc-break)：中斷 [arc:call](./op-arc-call) 或 arc:enum 迭代。
* [arc:continue](./op-arc-continue)：跳過本次 [arc:call](./op-arc-call) 或 arc:enum 迭代。
* [arc:first](./op-arc-first)：為第一次迭代提供特殊的處理。
* [arc:last](./op-arc-last)：為最後一次迭代提供特殊的處理。
