@@ -77,6 +77,8 @@ export default Demo;
7777
7878``` jsx
7979import React from ' react' ;
80+ import { PlusOutlined } from ' @ant-design/icons' ;
81+ import { Button } from ' antd' ;
8082import Form from ' ../demo/display' ;
8183
8284const schema = {
@@ -87,6 +89,7 @@ const schema = {
8789 description: ' 对象数组嵌套功能' ,
8890 type: ' array' ,
8991 widget: ' simpleList' ,
92+ ' add-widget' : ' addBtn' ,
9093 items: {
9194 type: ' object' ,
9295 properties: {
@@ -107,8 +110,16 @@ const schema = {
107110 },
108111};
109112
113+ const AddBtn = props => {
114+ return (
115+ < Button {... props} style= {{ width: ' 50%' }} icon= {< PlusOutlined / > }>
116+ 新增一条
117+ < / Button>
118+ );
119+ };
120+
110121const Demo = () => {
111- return < Form schema= {schema} / > ;
122+ return < Form widgets = {{ addBtn : AddBtn }} schema= {schema} / > ;
112123};
113124
114125export default Demo ;
@@ -374,6 +385,7 @@ const Demo = () => {
374385
375386export default Demo ;
376387```
388+
377389<br >
378390<br >
379391
@@ -410,4 +422,56 @@ const Demo = () => {
410422};
411423
412424export 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