javascript - javascript(ReactJS),如何执行函数的引用
问题描述
如果我有一个我想在 a 中使用的函数onClick
,比如这个
*使用 ReactJS 和 Semantic-UI
<Table.HeaderCell
onClick={this.handleSort(items)}
>
其中函数返回函数的引用,例如 this
handleSort = (items) => () => {
console.log('now')
}
那么,如何在 onClick 事件之外执行此功能?什么不起作用:
componentDidMount() {
this.handleSort.call(items);
this.handleSort(items);
}
解决方案
handleSort
返回一个函数,您需要使用 调用它()
,如下所示:
componentDidMount() {
this.handleSort(items)();
}
推荐阅读
- java - JAVA:使用多线程将 ZipFile 复制到 ZipOutputStream
- python - ibm_boto3 在 Mac OS 上与 scikit-learn 的兼容性问题
- angular - 角度材料数据表未填充数据
- android - 生成签名 APK 时的 Android Studio 错误:插件 Android 支持中的异常
- visual-studio-code - “代码 。” 命令不起作用
- android - Android Studio SDK & System Image 安装问题
- android - 如何从 recyclerView 适配器访问 SharedPrefences?
- python - Play videos (with audio) under Python
- ns2 - NS2-协议修改 - dymo
- asp.net - is there a way to create a custom action for a standard web api "publish" via visual studio?