老师您好!我的代码是这样的:
constructor() {
super();
this.state = {
projectNumber: ''
};
}
componentWillMount() {
var myFetchOptions = {
method: 'GET'
};
fetch("。。。。。",myFetchOptions)
.then(response => response.json())
.then(json => this.setState({projectNumber: json}));
};
render(){
console.log(this.state);
console.log(this.state.projectNumber.dataList.length)
然后我从后台获取到的json格式格式是这样的;
{
"errcode": 0,
"dataList": [
{
"id": 1,
"pro_num": "0-不涉及"
},
{
"id": 2,
"pro_num": "1008"
},
{
"id": 3,
"pro_num": "1019"
},
{
"id": 4,
"pro_num": "1079"
},
{
"id": 5,
"pro_num":
但是想要获取dataList的length会报错???
轻松入门 React 开发,React Router 4 与 Webpack 2 完美升级项目
了解课程