我有以下JSON数据,需要每5秒以src
状态进行更新。我尝试在控制台中打印数据,该数据显示完全正常,但是每次睡眠5秒后状态都不会得到更新。
日志Json的JSON数据示例
var Logs={
Router:[{"a":"1"}],
Validation:[{"b":"1"}],
Transformation:[{"c":"1"}],
Execution:[{"d":"1"}],
Response:[{"e":"1"}]
}
这是我的代码
var LogData={};
LogData["Router"]=Logs.Router;
//Requesting Router
_this.setState({
cssRequest:ClassProgressDone,
src:LogData,
});
console.log(LogData);
_this.sleep(5000).then(() => {
LogData["Validation"]=Logs.Validation;
console.log(LogData);
_this.setState({
cssValidate:ClassProgressDone,
src:LogData,
});
_this.sleep(5000).then(() => {
LogData["Transformation"]=Logs.Transformation;
console.log(LogData);
_this.setState({
cssTransform:ClassProgressDone,
src:LogData,
});
_this.sleep(5000).then(() => {
LogData["Execution"]=Logs.Execution;
console.log(LogData);
_this.setState({
cssExecution:ClassProgressDone,
src:LogData,
});
_this.sleep(5000).then(() => {
LogData["Response"]=Logs.Response;
console.log(LogData);
_this.setState({
cssCompleted:ClassProgressDone,
src:LogData,
});
});
});
});
});
睡眠功能
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
任何提示我在做什么错了吗?