> ## 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:map

> 使用 arc:map 將一個物件中的屬性對映到另一個物件中的屬性，從源物件讀取並以新名稱寫入目標物件。

export const siteNameShort = "知行之橋";

arc:map 關鍵字用來將物件中的屬性對映到另一個物件的屬性。從一個物件中讀取屬性，並使用在 map 字串中指定的新名稱寫到另一個物件中。arc:map 關鍵字不會清除目標物件，僅僅是增加了新屬性。或者，如果在目標物件中已存在相同的屬性名，則對應的屬性值將被覆蓋，其它屬性則保持原樣。

## 參數

* **to**：要將屬性寫入的物件的名稱。
* **from**：要從中讀取屬性的物件的名稱。
* **map**：屬性名稱的清單，指定了目標物件中的屬性名稱，然後是源物件中的屬性名稱。例如：可以使用下面的語法，將帶有一個字首的屬性對映到帶有另一個字首的屬性：

  `customer:\* = soap:\*`

  任何不是有效屬性名稱的字元都將被忽略，並用於劃分名稱的結尾。

## 控制屬性

* 此關鍵字沒有任何控制屬性。

## 範例

對映三個屬性：map 是一系列 “to” 屬性名，後跟 “from” 屬性名。

```xml theme={null}
<arc:set item="item1" attr="var1" value="x"/>
<arc:set item="item1" attr="var2" value="y"/>
<arc:set item="item2" attr="attr1" value="z"/>
<arc:map to="item2" from="item1" map="attr1=var1, attr2=var2"/>
```

在本例中，item1 的 var1 和 var2 屬性分別被對映到 item2 的 attr1 和 attr2。attr1 屬性，在 item2 中值被設為 z，被 item1 中 var1 的值 x 覆蓋。attr2 屬性，在 item2 中不存在，被建立且值被設為 y，即在 item1 中 var2 的值。

可以將多個屬性從具有一個字首的物件對映到具有不同字首的物件。這對於將字首從應用程式字首（例如 soap:\*）更改為業務域字首（例如 customer:\*）時會很有用。下面的範例建立一個從物件 soapout 中所有 soap:\* 屬性到物件 customer 中以 customer:\* 為字首的屬性對映：

```xml theme={null}
<arc:map from="soapout" to="customer" map="customer:* = soap:*"/>
```

將一個專案的所有屬性複製到另一個物件：

```xml theme={null}
<arc:map from="copyfrom" to="copyto" map="* = *"/>
```

## 另請參閱

* [arc:set](./op-arc-set)：設定物件的屬性。
