File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
demo/src/index/views/Demo/schemaTypes/24.uiSchema(表达式) Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff 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
119134uiSchema = {
You can’t perform that action at this time.
0 commit comments