我有此代码:
constructor(props){
super(props);
this.state={
article: [],
descArt: []
};
}
article
在用axios
拨打电话后填充:
click to see console.log(this.state.article)
然后,我尝试在render()
中打印一个元素而没有成功:
render(){
return(
<Form>
<Row>
<FormGroup className="col-md-12">
<Label for="exampleEmail" md={3}>ADR</Label>
<Col md={6}>
<p>{this.state.article[0].ADR}</p>
</Col>
</FormGroup>
</Row>
this.setstate.article.ADR
或this.state.article[0].ADR
(在两种情况下,ADR
均未定义。
为什么?在console.log上有效!
通话组件:
这是通话成功:
componentDidMount(){
const stato = { service: "ArticoliCerca", article: this.props.article};
getData(this, stato);
successCallback(service, response) {
switch(service){
case 'ArticoliCerca':
this.setState({
article: response.data.dati,
});
break;