@@ -77,6 +77,8 @@ export default Demo;
77
77
78
78
``` jsx
79
79
import React from ' react' ;
80
+ import { PlusOutlined } from ' @ant-design/icons' ;
81
+ import { Button } from ' antd' ;
80
82
import Form from ' ../demo/display' ;
81
83
82
84
const schema = {
@@ -87,6 +89,7 @@ const schema = {
87
89
description: ' 对象数组嵌套功能' ,
88
90
type: ' array' ,
89
91
widget: ' simpleList' ,
92
+ ' add-widget' : ' addBtn' ,
90
93
items: {
91
94
type: ' object' ,
92
95
properties: {
@@ -107,8 +110,16 @@ const schema = {
107
110
},
108
111
};
109
112
113
+ const AddBtn = props => {
114
+ return (
115
+ < Button {... props} style= {{ width: ' 50%' }} icon= {< PlusOutlined / > }>
116
+ 新增一条
117
+ < / Button>
118
+ );
119
+ };
120
+
110
121
const Demo = () => {
111
- return < Form schema= {schema} / > ;
122
+ return < Form widgets = {{ addBtn : AddBtn }} schema= {schema} / > ;
112
123
};
113
124
114
125
export default Demo ;
@@ -374,6 +385,7 @@ const Demo = () => {
374
385
375
386
export default Demo ;
376
387
```
388
+
377
389
<br >
378
390
<br >
379
391
@@ -410,4 +422,56 @@ const Demo = () => {
410
422
};
411
423
412
424
export default Demo ;
413
- ```
425
+ ```
426
+
427
+ 8 . 自定义 onAdd(添加)、onRemove(删除)
428
+
429
+ ``` jsx
430
+ import React from ' react' ;
431
+ import Form from ' ../demo/display' ;
432
+
433
+ const schema = {
434
+ type: ' object' ,
435
+ properties: {
436
+ listName2: {
437
+ title: ' 礼物配置' ,
438
+ description: ' 可以有多套配置方案' ,
439
+ type: ' array' ,
440
+ widget: ' simpleList' ,
441
+ props: {
442
+ onAdd: ' addFunc' ,
443
+ onRemove: ' removeFunc'
444
+ },
445
+ items: {
446
+ type: ' object' ,
447
+ properties: {
448
+ input1: {
449
+ title: ' {{`配置方案${rootValue.index + 1}`}}' ,
450
+ type: ' string' ,
451
+ required: true ,
452
+ },
453
+ },
454
+ },
455
+ },
456
+ },
457
+ };
458
+
459
+ const Demo = () => {
460
+ const methods = {
461
+ addFunc : (cb , { schema }) => {
462
+ alert (' 自定义新增' );
463
+ // 处理完成,执行内置逻辑
464
+ cb ();
465
+ },
466
+ removeFunc : (cb , { schema }) => {
467
+ alert (' 自定义删除' );
468
+ // 处理完成,执行内置逻辑
469
+ cb ();
470
+ }
471
+ };
472
+
473
+ return < Form schema= {schema} methods= {methods}/ > ;
474
+ };
475
+
476
+ export default Demo ;
477
+ ```
0 commit comments