我真的很困扰看起来很简单的问题。我正在使用React并尝试将变量设置为传递的状态。将变量设置为React中的子节点
这里是传递
{
"id": "6",
"FName": "Chris",
"LName": "Baker",
"Height": "6'2",
"Meds": [
{
"MedicationName": "acetaminophen",
"Doseage": "Take 2 daily with food",
"NumRefills": 2,
"RefillExp": "2017-05-31T15:38:50.02Z",
"FirstPrescribed": "2017-05-31T15:38:50.02Z",
"WFID": "string"
}
]
}
我能够设定在母公司层面的变量就好例如JSON ....
class App extends ReactComponent {
....
render() {
return (
....
<OverviewPane overview={this.state.PATIENT}/>
....
);
}
}
然后在概述窗格中,我能够根据预期的JSON数据设置字段。 (见下文)
class OverviewPane extends ReactComponent {
....
render() {
return (
....
<td>{this.props.overview.map(function(P){return <label key={P.id}> First Name: {P.FName}</td>
....
);
}
}
但是我不能够得到吃药所以我尝试有以下...
class App extends ReactComponent {
....
render() {
return (
....
<MedicationsPane meds={this.state.PATIENT.Meds[0]}/>
....
);
}
}
而且在药物窗格......
class MedicationsPane extends React.Component {
...
render() {
return (
<List>
{this.props.meds.map(function(Meds) {
return <ListItem justify='between' separator='horizontal' key={Meds.MedicationName}>{Meds.MedicationName}</ListItem>;
})}
</List>
);
}
}
当我做了上述但我得到的错误“不能读取属性'0'未定义。任何想法如何从JSON中提取药物?
你能分享,你实际调用您的要求,或者你设置的默认状态,你刚才提到的JSON对象?作为this.state.PATIENT越来越不确定。 –