-
items可以相互联动吗?比如第一个item有个下拉选项选择了某个值,新添加的item的下拉框就不能选择这个值,目前尝试了很多,都不能实现 |
Beta Was this translation helpful? Give feedback.
Answered by
janryWang
Jul 22, 2021
Replies: 2 comments 8 replies
-
dependencies:["..[+].name","..[-].name"] 可以取到下一行数据和上一行数据 |
Beta Was this translation helpful? Give feedback.
7 replies
Answer selected by
janryWang
-
import {
ArrayItems,
DatePicker,
Editable,
FormButtonGroup,
FormItem,
Input,
Radio,
Select,
Space,
Submit,
} from '@formily/antd';
import { createForm, onFieldValueChange } from '@formily/core';
import { createSchemaField, FormProvider } from '@formily/react';
const SchemaField = createSchemaField({
components: {
FormItem,
Editable,
DatePicker,
Space,
Radio,
Input,
Select,
ArrayItems,
},
});
const form = createForm({
initialValues: {
string_array: ['1', '2'],
},
effects: () => {
onFieldValueChange('string_array.*.input', (field, form) => {
console.log('name changed:', field.value, form);
const index = field.path.segments[1]; // 获取当前字段在数组中的索引
const nextIndex = index + 1; // 获取下一个字段的索引
form.setFieldState(`string_array.${nextIndex}.input`, (state) => {
state.value = field.value;
});
});
},
});
const schema = {
type: 'object',
properties: {
string_array: {
type: 'array',
'x-component': 'ArrayItems',
'x-decorator': 'FormItem',
title: '字符串数组',
items: {
type: 'void',
'x-component': 'Space',
properties: {
input: {
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'Input',
'x-reaction': "{{ console.log('123') }}",
title: 'input',
},
},
},
properties: {
add: {
type: 'void',
title: '添加条目',
'x-component': 'ArrayItems.Addition',
},
},
},
},
};
export default () => {
return (
<FormProvider form={form}>
<SchemaField schema={schema} />
<FormButtonGroup>
<Submit onSubmit={console.log}>提交</Submit>
</FormButtonGroup>
</FormProvider>
);
}; |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dependencies:["..[+].name","..[-].name"] 可以取到下一行数据和上一行数据