小编Jer*_*eme的帖子

如何在React上映射数组并将其作为道具正确传递给子组件?

我有一个子组件PatientRow,它正在从其父对象的props中接收映射的患者数组ObsTabel。奇怪的是,PatientRow从未渲染,我也无法在React Dev工具上找到PatientRow组件。另一方面,如果我只是通过患者数组,则将其映射PatienRow到组件中即可渲染,但这不是我想要的。我想将数组映射为ObsTabel&传递给数组,PatientRow以便行是具有各自状态的单个组件。如果您能找到我的错误,请告诉我。注意:ObsTable有一个父组件,从该组件接收作为道具传递的患者数组。文件结构-ParentComponent(with patient array).js>ObsTable.js>PatientRow.js


This doesn’t exist in DOM 

export default class PatientRow extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            disabled: false
        };

    }

    render() {

        const { id, label, name, room, timestamp, observationLevel, roomStatus, patient, index } = this.props;
        console.log(this.props);

        return (
            <tbody>

                <tr key={id} >
                    <td>{label}</td>
                    <td>{name}</td>
                    <td>{observationLevel}</td>
                    <td>{roomStatus}</td>
                    <td>{timestamp} </td>

                    <td>


                        <div>
                            <Button> Awake </Button>
                            <Button>Asleep/Breathing</Button>
                        </div>

                        <Button> View Room </Button>

                        <div>
                            <Button>Awake </Button> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-props react-component

0
推荐指数
1
解决办法
46
查看次数