Mapping 映射

基本用法

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "mapping",
  5. "value": "1",
  6. "map": {
  7. "1": "第一",
  8. "2": "第二",
  9. "3": "第三",
  10. "*": "其他"
  11. }
  12. }
  13. }

渲染 HTML

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "mapping",
  5. "value": "2",
  6. "map": {
  7. "1": "<span class='label label-info'>漂亮</span>",
  8. "2": "<span class='label label-success'>开心</span>",
  9. "3": "<span class='label label-danger'>惊吓</span>",
  10. "4": "<span class='label label-warning'>紧张</span>",
  11. "*": "<span class='label label-default'>其他:${type}</span>"
  12. }
  13. }
  14. }

支持数组

1.5.0 及以上版本

如果返回值是数组会显示为多个

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "mapping",
  5. "value": ["1", "2", "3", "4", "5"],
  6. "map": {
  7. "1": "<span class='label label-info'>漂亮</span>",
  8. "2": "<span class='label label-success'>开心</span>",
  9. "3": "<span class='label label-danger'>惊吓</span>",
  10. "4": "<span class='label label-warning'>紧张</span>",
  11. "*": "<span class='label label-default'>其他</span>"
  12. }
  13. }
  14. }

用作 Field 时

当用在 Table 的列配置 Column、List 的内容、Card 卡片的内容和表单的 Static-XXX 中时,可以设置name属性,映射同名变量

Table 中的列类型

```schema: scope=”body” { “type”: “table”, “data”: { “items”: [ { “id”: “1”, “type”: “1” }, { “id”: “2”, “type”: “2” }, { “id”: “3”, “type”: “3” } ] }, “columns”: [ { “name”: “id”, “label”: “Id” },

  1. {
  2. "name": "type",
  3. "label": "映射",
  4. "type": "mapping",
  5. "map": {
  6. "1": "<span class='label label-info'>漂亮</span>",
  7. "2": "<span class='label label-success'>开心</span>",
  8. "3": "<span class='label label-danger'>惊吓</span>",
  9. "4": "<span class='label label-warning'>紧张</span>",
  10. "*": "其他:${type}"
  11. }
  12. }
  13. ]

}

  1. List 的内容、Card 卡片的内容配置同上
  2. ### Form 中静态展示
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "data": {
  7. "type": "2"
  8. },
  9. "body": [
  10. {
  11. "type": "static-mapping",
  12. "name": "type",
  13. "label": "映射",
  14. "map": {
  15. "1": "<span class='label label-info'>漂亮</span>",
  16. "2": "<span class='label label-success'>开心</span>",
  17. "3": "<span class='label label-danger'>惊吓</span>",
  18. "4": "<span class='label label-warning'>紧张</span>",
  19. "*": "其他:${type}"
  20. }
  21. }
  22. ]
  23. }

布尔值映射

```schema: scope=”body” { “type”: “form”, “data”: { “type”: true }, “body”: [ { “type”: “static-mapping”, “name”: “type”, “label”: “映射”, “map”: { “1”: ““, “0”: ““ } } ] }

  1. 或者
  2. ```schema: scope="body"
  3. {
  4. "type": "form",
  5. "data": {
  6. "type": true
  7. },
  8. "body": [
  9. {
  10. "type": "static-mapping",
  11. "name": "type",
  12. "label": "映射",
  13. "map": {
  14. "true": "<span class='label label-info'>开</span>",
  15. "false": "<span class='label label-default'>关</span>"
  16. }
  17. }
  18. ]
  19. }

远程拉取字典

since 1.1.6

通过配置 source 接口来实现,接口返回字典对象即可,数据格式参考 map 配置。

```schema: scope=”body” { “type”: “form”, “data”: { “type”: “2” }, “body”: [ { “type”: “mapping”, “name”: “type”, “label”: “映射”, “source”: “/api/mapping” } ] }

  1. > 默认 source 是有 30s 缓存的,通常字典数据不长变更。如果想修改,请参考 [API]($docs-types-api) 文档配置缓存。
  2. ### 关联上下文变量
  3. > since 1.1.6
  4. 同样通过配置 `source` 来实现,只是格式是取变量。
  5. > 注意:当数据域里的变量值为`$$`时, 表示将所有接口返回的`data`字段值整体赋值到对应的 key
  6. ```schema: scope="body"
  7. {
  8. "type": "form",
  9. "initApi": {
  10. "url": "/api/mapping",
  11. "method": "get",
  12. "responseData": {
  13. "zidian": "$$$$",
  14. "type": "2"
  15. }
  16. },
  17. "body": [
  18. {
  19. "type": "mapping",
  20. "name": "type",
  21. "label": "映射",
  22. "source": "$${zidian}"
  23. }
  24. ]
  25. }

占位文本

通过 placeholder 可以控制数据不存在时的展现

  1. {
  2. "type": "page",
  3. "body": {
  4. "type": "mapping",
  5. "placeholder": "数据不存在",
  6. "map": {
  7. "1": "第一",
  8. "2": "第二",
  9. "3": "第三",
  10. "*": "其他"
  11. }
  12. }
  13. }

属性表

属性名 类型 默认值 说明
className string 外层 CSS 类名
placeholder string 占位文本
map object 映射配置
source string or API API数据映射