本系列文章是本人学习相关知识时所积累的笔记,以记录自己的学习历程,也为了方便回顾知识;故文章内容较为随意简练,抱着学习目的来的同学务必转移他处,以免我误人子弟~
项目使用 antd 开发前端组件,在使用 Select 时,mode=tags,出现了以下报错
Uncaught Error: must set key for <rc-animate> children at Animate.js:202
at Array.map (<anonymous>)
at Animate.render (Animate.js:197)
at finishClassComponent (react-dom.development.js:8389)
at updateClassComponent (react-dom.development.js:8357)
at beginWork (react-dom.development.js:8982)
at performUnitOfWork (react-dom.development.js:11814)
at workLoop (react-dom.development.js:11843)
at renderRoot (react-dom.development.js:11874)
at performWorkOnRoot (react-dom.development.js:12449)
解决方案在initialValue这里设置一个空数组 [ ]
public formItemsDataEdit: IFormItemsData = {
items: [{
field: ResourceField.name,
}, {
field: ResourceField.type,
}, {
field: ResourceField.firstCategory,
initValue: [],
}, {
field: ResourceField.secondCategory,
initValue: [],
}, {
field: ResourceField.experience,
}, {
field: ResourceField.tags,
initValue: [],
}],
isUpdate: true,
};
因为在表单构建过程中,会先对表单内数据初始化,而 mode=tags 的 Select 表单项是不能接受非数组的数据的,因而报错
export default class ResourceEditView extends React.Component<IResourrceEditProps, IState> {
constructor(props: any) {
super(props);
let fields = {};
for (let formItem of this.props.formItemsData.items) {
fields[formItem.field] = {
value: formItem.initValue ? formItem.initValue : "",
};
}
this.state = {
fields,
};
......