0
中的API提供以如下方式數據(JSON格式):Reactjs:如何在反應-Redux的形式取子對象數據
[
{
"_id": 1,
"name": "XYZ",
"address": {
"street": "",
"pin_code": 69856,
"country": "US",
"city": "Boston"
}
}
]
如何可以取從address
從以上響應中的字段?我正在使用react-redux表單。
這裏是表單字段:
import React, {Component} from 'react';
import {reduxForm} from 'redux-form';
class FetchUserForm extends Component {
render() {
const { fields: {name, street, country}, handleSubmit } = this.props;
return(
<form onSubmit={handleSubmit}>
<div className='form-group'>
<input type='text' className='form-control' placeholder='User Name' {...name}/>
</div>
<div className='form-group'>
<input type='text' className='form-control' placeholder='Street' {...street}/>
</div>
<div className='form-group'>
<input type='text' className='form-control' placeholder='country' {...country}/>
</div>
<button type='submit' className='btn btn-primary'> Update </button>
<button type='reset' className='btn btn-default'> Cancel </button>
</form>
);
}
}
export default reduxForm ({
form: 'FetchUserForm',
fields: ['name', 'street', 'country']
},null, { fetchUser })(FetchUserForm);
正如所看到的,我試圖從數據的子對象獲取街道和鄉村。有人可以幫助我獲得表格中的實際數據。現在我得到null