Skip to content

Commit

Permalink
修正翻译
Browse files Browse the repository at this point in the history
  • Loading branch information
hotlong committed Nov 7, 2023
1 parent 6d084f0 commit ca87b39
Showing 1 changed file with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Data Mapping
# 数据映射

Data mapping is a powerful feature that allows users to fetch variable values from the current data chain by using template strings, such as ${xxx} or $xxx. This method is primarily used in scenarios like template strings, custom API request body formats, etc.
数据映射是一种强大的功能,它允许用户通过使用模板字符串,如 ${xxx} $xxx,来获取当前数据链中的变量值。这种方法主要用于模板字符串、自定义 API 请求数据体格式等场景。

### Customizing API Request Body Data Format
When submitting a form interface, if the default request body data format of AMIS does not meet your expectations, you can use data mapping to customize the required data format. For example, if your backend interface only supports a specific input data structure, you can customize the data format by configuring the **data** attribute of the API.
For instance:

### 自定义 API 请求体数据格式
在表单提交接口时,如果 AMIS 默认的请求体数据格式不符合你的预期,你可以使用数据映射来定制所需的数据格式。例如,如果你的后端接口仅支持特定的输入数据
结构,你可以通过配置 API 的 **data** 属性来实现数据格式的自定义。
例如:

```json
{
Expand All @@ -23,21 +25,21 @@ For instance:
{
"type": "input-text",
"name": "name",
"label": "Name:"
"label": "姓名:"
},
{
"name": "email",
"type": "input-text",
"label": "Email:"
"label": "邮箱:"
}
]
}
}
```

### Complex Configuration
AMIS allows the use of & as a key for data mapping to expand the configured variables. This means you can expand all the properties of an object and concatenate them in data.
For example:
### 复杂配置
AMIS 允许使用 & 作为数据映射的键,以展开所配置的变量。这意味着你可以将一个对象中的所有属性展开并拼接在 data 中。
例如:

```json
{
Expand Down Expand Up @@ -68,20 +70,20 @@ For example:
{
"type": "input-text",
"name": "name",
"label": "Name:"
"label": "姓名:"
},
{
"name": "email",
"type": "input-text",
"label": "Email:"
"label": "邮箱:"
}
]
}
}
```

### Extracting Values from Arrays
You can configure the data attribute of the API to extract only specific variables from an array and form a new array.
### 从数组提取值
你可以配置 API 的 data 属性来仅提取数组中的特定变量,并组成新的数组。

```json
{
Expand All @@ -104,7 +106,7 @@ You can configure the data attribute of the API to extract only specific variabl
{
"type": "input-table",
"name": "table",
"label": "Table",
"label": "table",
"columns": [
{
"label": "A",
Expand Down Expand Up @@ -134,18 +136,18 @@ You can configure the data attribute of the API to extract only specific variabl
```

### Namespace
AMIS supports fetching data from different namespaces, such as global variables, localStorage, sessionStorage, and cookies.
AMIS 支持从不同的命名空间中获取数据,如全局变量、localStoragesessionStorage cookies

- window refers to global variables.
- ls refers to localStorage. If the value is a JSON object, it can be used directly as an object, for example: ${ls:xxxxxlocalStrorageKey.xxxx}
- ss refers to sessionStorage, similar to above.
- cookie refers to cookies, similar to above.
- window 即全局变量
- ls localStorage, 如果值是 json 对象,可以直接当对象用比如:${ls:xxxxxlocalStrorageKey.xxxx}
- ss sessionStorage,同上。
- cookie cookies,同上

For example:
比如:

```json
{
"type": "page",
"body": "The current page title is: <span class='label label-info'>${window:document[title]}</span>"
"body": "当前页面标题为:<span class='label label-info'>${window:document[title]}</span>"
}
```
```

0 comments on commit ca87b39

Please sign in to comment.