【发布时间】:2017-04-06 11:30:27
【问题描述】:
API 以下列方式提供数据(JSON 格式):
[
{
"_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
【问题讨论】:
标签: reactjs react-redux react-redux-form