javascript - TypeError: undefined is not an object ('_this.props')
问题描述
我无法解决这个问题。你能帮助我吗。评估“this.props.speciesSelection.modalize”
<BarcodeInput
speciesSelection={this.props.speciesSelection}
species={species[0]}
barcode={{ manufacturerValue: "", codeValue: "" }}
onChangeText={this.onChangeText}
/>
class BarcodeInput extends React.Component<Props, State> {
onPrefixPress = () => {
Keyboard.dismiss();
this.props.speciesSelection.modalize.open();
this.props.speciesSelection.modalizeOpened = true;
}
当我触摸到按钮 onPrefixPress 时的红框
解决方案
看起来您正在尝试调用未定义的函数(通过道具传递)。使speciesSelection
道具可选。
interface Props {
species: Species;
barcode: BarcodeState;
speciesSelection?: any;
onChangeText: (prop: keyof BarcodeState, value: string) => void;
}
interface State { }
class BarcodeInput extends React.Component<Props, State> {
onPrefixPress = () => {
Keyboard.dismiss();
this.props.speciesSelection && this.props.speciesSelection.modalize.open();
this.props.speciesSelection && this.props.speciesSelection.modalizeOpened = true;
}
或检查为什么它未定义。
推荐阅读
- python - 确定 tkinter UI 类属性是否已从外部模块更改的最佳方法是什么?
- javascript - Firebase 数据库打印数据并获取每个元素的值
- java - 如何在 2D 矩阵中找到对角线的总和?
- oracle - CallableStatement PL/SQL 未在 jsp 中插入数据库
- install4j - 在 install4j 中,executeScheduleUpdate 是如何工作的?
- c# - .NET Core 3 中 CreateToken 和 CreateJwtSecurityToken 的区别
- javascript - Bootsrap 模态未显示
- css - 如何在 .RPres R 演示文稿中编辑标题幻灯片样式?
- flutter - 使用 ListTile() 将从 Api 加载的图像排列到 Flutter 中的两列
- rest - 搜索 SSN 的 RESTful API 最佳实践