asyncgetData(start){const_self=this;varresponse=[];if(start==0){try{//letresponse=awaitfetch('mock-data/selectData01.json').then(function(response){//returnresponse.json();//第1个//}).then(function(responseThenData){////console.log('responseThenData=',responseThenData);//returnresponseThenData//第2个//}).catch(function(e){//console.log("Oops,error");//});response=awaitfetch('mock-data/selectData01.json').then(function(response){returnresponse.json();})returnresponse;//第3个}catch(e){console.log("Oops,error",e);}}elseif(start==1){try{response=awaitfetch('mock-data/selectData02.json').then(function(response){returnresponse.json();})returnresponse;//第3个}catch(e){console.log("Oops,error",e);}}elseif(start==2){try{response=awaitfetch('mock-data/selectData03.json').then(function(response){returnresponse.json();})returnresponse;//第3个}catch(e){console.log("Oops,error",e);}}elseif(start==3){try{response=awaitfetch('mock-data/selectData04.json').then(function(response){returnresponse.json();})returnresponse;//第3个}catch(e){console.log("Oops,error",e);}}elseif(start==4){try{response=awaitfetch('mock-data/selectData05.json').then(function(response){returnresponse.json();})returnresponse;//第3个}catch(e){console.log("Oops,error",e);}}}componentDidMount(){const_self=this;varkey=true;letdataReadStart=0;_self.getData(dataReadStart).then(function(responseThenData){//console.log('responseThenData=',responseThenData['dataChinaTelecom']['regionData']);_self.setState({tableBody:responseThenData['dataChinaTelecom']['emergencyTableData'],tableHead:responseThenData['dataChinaTelecom']['emergencyTableHeader']})}).then(function(){//console.log('abc')}).catch(function(e){console.log("promise,error=",e);});//varkey=true;//newPromise(function(resolve,reject){//if(key){//resolve('成功了')//}else{//reject('被拒绝')//}//}).then(function(value){//console.log(value);//key=true123//},function(rej){//console.log('---------resultreject');//console.log(rej);//})dataReadStart=dataReadStart+1;setInterval(function(){letdataPromise=_self.getData(dataReadStart);console.log('dataPromise=',dataPromise)dataPromise.then(function(responseThenData){//console.log('responseThenData=',responseThenData['dataChinaTelecom']['regionData']);_self.setState({tableBody:responseThenData['dataChinaTelecom']['emergencyTableData'],tableHead:responseThenData['dataChinaTelecom']['emergencyTableHeader']})}).then(function(){//console.log('abc')}).catch(function(e){console.log("promise,error=",e);});if(dataReadStart+1==5){dataReadStart=0;}else{dataReadStart=dataReadStart+1;}},30000)//ECMAScript定义了Undefined、Null、Boolean、String、Number、Object6种类型//其中Undefined和Null都是只包含一个值得特殊类型,分别为undefined和null//因此根据定义undefined和null分属不同类型//使用===运算符返回false//当声明的变量未初始化时,该变量的默认值是undefined,而null则用于表示尚未存在的对象}这里if能不能缩简到一个
三国纷争
凤凰求蛊
相关分类