Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.
/ rc-form-array Public archive

创建每一项带 key 的数组,方便在 rc-form 中渲染数组表单

License

Notifications You must be signed in to change notification settings

frontlich/rc-form-array

Repository files navigation

安装

npm install rc-form-array --save

使用

import { createFormArray } from 'rc-form-array';

创建

createFormArray<T>(list: T[], minLen = 0)

示例:this.state = { students: createFormArray([]) };

新增

add(...newItems: T[]): FormArray<T>

示例:this.setState({ students: students.add({ name: 'xiaoming', age: 18 }) });

删除

delete(...keys: number[]): FormArray<T>

示例:this.setState({ students: students.delete(0) });

获取

get(key: number): T

示例:students.get(0)

更新

set(key: number, item: T): FormArray<T>

set(key: number, fn: (item: T) => T): FormArray<T>

示例:this.setState({ students: students.set(0, { name: 'xiaohong', age: 18 }) });

this.setState({ students: students.set(0, (student) => ({ ...student, name: 'xiaohong' })) });

渲染

render(fn: (value: T, key: number, index: number) => any)

示例:

students.render((item, key, index) => 
  getFieldDecorator(`students[${key}].name`, {
    initialValue: item && item.name
  })(
    <Input/>
  )
)

示例详见demo;

About

创建每一项带 key 的数组,方便在 rc-form 中渲染数组表单

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published