reactjs - ReactJS 多箭头函数
问题描述
.then((myJson) => this.setState({example: myJson},() => this.toggleModal()));
我正在从我的 API 中获取数据,然后我调整我的模态以显示一些数据,但是我需要this.example()
在模态显示之前执行函数,我已经尝试过;
.then((myJson) => this.setState({example: myJson},() => this.example() ,() => this.toggleModal()));
但是这种方式toogleModal()
是不执行的!我该如何解决这个问题?
解决方案
就像@Developer 说的,试试吧:
.then((myJson) => this.setState({example: myJson},() => {
this.example();
this.toggleModal();
}));
推荐阅读
- python - 为什么所有的测试用例都没有通过?回文程序
- javascript - 如何“强制”Rails 读取 JS 文件,以便函数可用?
- poloniex - Poloniex websocket API 不断断开连接
- angular - Angular httpClient 无法读取未定义的属性未定义
- nginx - Webmin 保存配置文件失败:配置无效:nginx:
- flutter - 每当我运行我的 Flutter 应用程序时,我都会收到一个 null 错误
- reactjs - 如何在反应日历中格式化日期?
- ruby-on-rails - 如何在ruby中销毁除当前用户(管理员)之外的所有用户
- c++ - 在重叠模式下使用 WSASend 时,我应该何时释放缓冲区?
- loadrunner - 无法使用 LoadRunner 2021 录制 Java 桌面应用程序