gpt4 book ai didi

swift - ReactNative : In the navigation bar on the right button, 点击事件不起作用,出现错误

转载 作者:行者123 更新时间:2023-11-30 12:26:56 24 4
gpt4 key购买 nike

react native :我使用 react-navigation 组件。

在右侧导航栏中,单击事件不工作

`_newCustomer() {
alert('点击新建');
}
static navigationOptions = {
title: '客户列表',
headerRight: (
<Button title={'添加客户'} onPress={this._newCustomer.bind(this)}/>
),
}

错误:

undefined is not an object(evaluating 'this._newCustomer')

最佳答案

问题是因为您尝试从静态函数调用 this._newCustomer,而 this 未定义,因为您处于静态函数中。

如果你看React Navigation Docs您将在示例中看到他们使用匿名函数。这样做,或者调用另一个静态函数。

关于swift - ReactNative : In the navigation bar on the right button, 点击事件不起作用,出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44065736/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com