简体   繁体   English

ReactJs中的警告:数组或迭代器中的每个子代都应具有唯一的“键”属性

[英]Warning in ReactJs: Each child in an array or iterator should have a unique “key” prop

I'm having this warning: 我收到此警告:

Warning: Each child in an array or iterator should have a unique "key" prop, in in DepartmentRow (created by FilterableTable). 警告:数组或迭代器中的每个子代都应在DepartmentRow(由FilterableTable创建)中具有唯一的“键”道具。

This is where DepartmentRow appears in FilterableTable: 这是DepartmentRow出现在FilterableTable中的位置:

showListOfDepartmentsToBeFiltered = () => {
    const {
        users
    } = this.props;

    if ( users.length > 0 ) {
        let row = [];
        users.filter(function(user, index) {
            return users.map(item => item.department.trim()).indexOf(user.department.trim()) === index;
        }).forEach(r => {
            row.push(
                <DepartmentRow key={r.departament} data={r} handleChange={(e) => this.handleChange(e)}/>
            );
        });
        return (
            <div>
                <table className={styles.departmentTable}><tr><thead>Departments</thead></tr>{row}</table>
            </div>
        );
    }
    return false;
}

And this is DepartmentRow component: 这是DepartmentRow组件:

class DepartmentRow extends React.Component {
    constructor(props) {
        super(props);
    }
    render() {
        return(
            <tbody>
            <tr>
                <td><div><input type="checkbox" name="ListOfDepartments" value={this.props.data.department} onChange={(e)=>this.props.handleChange(e)}/>
                    <label htmlFor="ListOfDepartments">{this.props.data.department}</label></div>
                </td>
            </tr>
            </tbody>
        );
    }
}
DepartmentRow.propTypes = {
    data: PropTypes.object,
    handleChange: PropTypes.func
};

How can I solve it? 我该如何解决? Thank you! 谢谢!

Looks like it might just be a typo? 看起来可能只是拼写错误?

row.push(
  <DepartmentRow key={r.departament} data={r} handleChange={(e) => this.handleChange(e)}/>
);

r.departament -> r.department r.departament -> r.department

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数组或迭代器中的每个子项都应该具有唯一的键 prop reactjs - Each child in an array or iterator should have unique key prop reactjs 数组或迭代器中的每个子代在reactjs中都应具有唯一的“键”道具 - Each child in an array or iterator should have a unique “key” prop in reactjs 警告:数组或迭代器中的每个子代都应具有唯一的“键”道具 - Warning :Each child in an array or iterator should have a unique “key” prop ReactJS警告:数组或迭代器中的每个子节点都应该有一个唯一的“key”prop - ReactJS Warning: Each child in an array or iterator should have a unique “key” prop index.js:2178警告:数组或迭代器中的每个子代都应具有唯一的“键”属性。 -reactjs - index.js:2178 Warning: Each child in an array or iterator should have a unique “key” prop. - reactjs 警告:数组或迭代器中的每个子代都应具有唯一的“键”道具。 li中已添加的关键道具 - Warning: Each child in an array or iterator should have a unique “key” prop.; key prop already added in li Reactjs:警告列表中的每个孩子都应该有一个唯一的“关键”道具 - Reactjs: Warning Each child in a list should have a unique "key" prop 持久警告:“即使已经设置了密钥,数组或迭代器中的每个子节点都应该具有唯一的&#39;密钥&#39;prop” - Persistent Warning: “Each child in an array or iterator should have a unique 'key' prop” even if key is already set Reactjs-数组或迭代器中的每个子代都应具有唯一的“键”道具。 如何动态地做到这一点? - Reactjs - Each child in an array or iterator should have a unique “key” prop. How to do that dynamically? “警告:”的简单解决方案:数组或迭代器中的每个子代都应具有唯一的“键”道具。 - Simple solution for “Warning: Each child in an array or iterator should have a unique ”key“ prop.”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM