react-native - 如何在 React-Native 中使用 event.value
问题描述
该事件在 React-Native 中不起作用。
这是文本输入。
<TextInput
id="name"
placeholder="name"
onChange = {this._inputChange}
/>
这就是 onChage 函数。
当我检查在 TextInput 中写入的 console.log(e.nativeEvent.id) 时,它显示未定义。
我猜 e.target.id 不能在 React-native 而不是 React 中使用。
你能推荐一些想法吗?
_inputChange = (e) => {
let nextState = {};
console.log(e.nativeEvent.id)
nextState[e.nativeEvent.id] = e.nativeEvent.value;
this.setState(nextState);
}
解决方案
我就是这样处理的...
handleChange = (field, value) ={
this.setState({ [field]: value });
}
<TextInput
onChangeText={this.handleChange.bind(this, 'name')}
...
/>
推荐阅读
- iframe - Sharepoint 嵌入 Webpart 找不到文件
- postman - 在基于 SAML/shibboleth 的网站上使用 Postman 进行身份验证,无需使用浏览器
- c - 为什么这显示“无效的类型转换”?
- winapi - 在 64 位和 32 位 (WOW64) 应用程序之间使用 WM_COPYDATA 是否安全?
- git - Kde SVN2Git。错误:存储库“my_repo”中的“branch_1”从分支“branch_2”分支,但后者不存在。无法继续
- sharepoint - 有没有办法将筛选器发送到 Sharepoint 列表并在 Web 部件中查看结果?
- html - Firefox 无法正确处理 svg 图像,但 Chrome 可以
- excel-formula - 我需要根据两个不同单元格中的信息在一个单元格中返回两个响应之一(留空或添加文本)
- python-3.x - MULTI 选项中的输入不会在 dash python 中产生预期的输出
- c# - 具有相等 DateTimeOffset 日期的单元测试返回错误