Skip to content

Commit 323889e

Browse files
committed
docs: 更新支持表达式文档
1 parent 570dd57 commit 323889e

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Created by Liu.Jun on 2020/7/22 11:07 下午.
3+
*/
4+
5+
export default {
6+
schema: {
7+
title: 'uiSchema 配置表达式',
8+
type: 'object',
9+
description: '<ui><li><b>rootFormData</b>:根节点的值</li><li><b>parentFormData</b>:当前父节点的值</li></ui>',
10+
properties: {
11+
age: {
12+
type: 'integer',
13+
title: '输入年龄',
14+
maximum: 80,
15+
minimum: 16,
16+
'ui:title': '{{ parentFormData.age > 18 ? "呵呵呵" : "嘿嘿嘿" }}',
17+
},
18+
bio: {
19+
type: 'string',
20+
title: 'Bio',
21+
minLength: 10,
22+
'ui:type': '{{ parentFormData.bio && parentFormData.bio.length ? "textarea" : "" }}'
23+
},
24+
selectWidgetOptions: {
25+
title: 'Custom select widget with options',
26+
type: 'string',
27+
// eslint-disable-next-line max-len
28+
'ui:style': '{{ parentFormData.selectWidgetOptions === "foo" ? { boxShadow: "0 0 6px 2px pink"} : { boxShadow: "0 0 6px 2px red"} }}',
29+
'ui:title': '{{ parentFormData.a === "1" ? "呵呵呵" : "嘿嘿嘿" }}',
30+
enum: [
31+
'foo',
32+
'bar'
33+
],
34+
enumNames: [
35+
'Foo',
36+
'Bar'
37+
]
38+
}
39+
}
40+
},
41+
formData: {
42+
a: '111'
43+
}
44+
};

packages/docs/docs/zh/guide/basic-config.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ export default {
103103
104104
用于配置表单展示样式,普通json数据,非 `JSON Schema` 规范
105105

106+
107+
#### ui-schema 表达式
108+
* `0.2` 版本之后,所有 `ui:xxx` 形式的配置都支持表达式(ui:options内不支持表达式以便区分)
109+
mustache 表达式可使用 `parentFormData``rootFormData` 两个内置变量。
110+
* `parentFormData` 当前节点父级的 FormData值
111+
* `rootFormData` 根节点的 FormData值
112+
113+
> 配置表达式会通过 `new Function` return 出结果,所以实际你在表达式中也可以访问到全局变量。
114+
115+
比如:(参考这里:[uiSchema 使用表达式](https://form.lljj.me/#/demo?type=uiSchema%28表达式%29)
116+
```
117+
'ui:title': `{{ parentFormData.age > 18 ? '呵呵呵' : '嘿嘿嘿' }}`
118+
```
119+
106120
:::tip
107121
* 配置数据结构和 `schema` 保持一致,所有的ui配置属性 `ui:` 开头
108122
* 也可以在 `ui:options` 内配置所有的属性,不需要 `ui:` 开头
@@ -114,6 +128,7 @@ export default {
114128
* `ui:hidden` `ui:widget` `ui:field` `ui:fieldProps` 不支持配置在 `ui:options`
115129
:::
116130

131+
117132
通用参数格式如下:
118133
```js
119134
uiSchema = {

0 commit comments

Comments
 (0)