无法更新文本输入中的值

时间:2019-11-14 05:02:43

标签: react-native textinput

我无法更新文本输入中的现有值。

<TextField
              label='Email Id'
              //placeholder={value_email}
              onChangeText={(email) => this.setState({ email })}
              value={value_email}
            />

value_email是

const value_email = this.state.userInfo.email;

谢谢。

2 个答案:

答案 0 :(得分:1)

result = [] receivedList = [] for d in data: if d['received_on'] not in receivedList: result.append(d) receivedList.append(d['received_on']) print(result) [{'customer_group': 'Life-time Buyer', 'id': '16e26a4a9f97fa4f', 'received_on': '2019-11-01 11:05:51'}, {'customer_group': 'Lead', 'id': '16db0dd4a42673e2', 'received_on': '2019-10-09 14:12:29'}] 将电子邮件设置为状态对象(this.state.email),但是您正在从this.setState({ email }中读取它。

如果将其设置为状态变量,则需要更改为 state.userInfo

答案 1 :(得分:0)

您正在设置状态wrog,如果要存储在对象userInfo状态中,请尝试以下操作:

  <TextInput
              label='Email Id'
               style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
              //placeholder={value_email}
             onChangeText = {(email) =>this.setState(prevState => { let userInfo = Object.assign({}, prevState.userInfo); userInfo.email = email 
            return { userInfo }; }) } 
              value={this.state.userInfo.email}
            />

现在您可以将值获取为const value_email = this.state.userInfo.email;