设置状态[react-native]后无法编辑inputText
在发送提取请求并保存状态数据并显示保存在inputText中的值后,我无法再编辑它。否则,它在我的输入清晰时起作用。设置状态[react-native]后无法编辑inputText
下面是代码:
第一步我取submiting为textInput后所需的数据上input.js
<TextInput
style={[ style.itemInfoMajor, global.alignRight ]}
onFocus={ onFocus }
onChangeText={ this._onChange }
onSubmitEditing={() => this._onSubmit(network) }
value={ value }
returnKeyType="done"
enablesReturnKeyAutomatically={ true }
clearButtonMode="always"
placeholder={ network }
placeholderTextColor="rgba(255, 255, 255, 0.25)"
autoCorrect={ false }
autoCapitalize="none"
clearTextOnFocus={ true }
/>
在list.js
我找回后加载的应用程序数据。
它那里有我设置的状态谁得到了inputText
componentWillMount() {
this._loadInitialState().done();
},
async _loadInitialState() {
try {
const value = await Storage.get('userData');
if (value !== null) {
this.setState({
data: value,
});
}
}
}
的价值和它的下面,我通过了国家的输入组件
<Input
onFocus={ this._handleFocus.bind(this, item) }
value={ value }
ref={ item }
key={ i }
network={ item }
/>
我加入少许视频现场观看问题:https://vid.me/8L9k 源代码在这里:https://github.com/statiks/statiks-react-native/blob/master/sources/input/index.js
如何编辑此输入值?在getInitialState
尝试设置值:
getInitialState() {
return {
...,
value: this.props.value
};
},
然后,将在TextInput使用this.state.value:
<TextInput
...
value={ this.state.value }
... />
然后,更新上改变自身状态的值:
_onChange(username) {
this.setState({ value: username });
},
它也看起来像你可能会传递不正确的值作为道具。你需要通过this.state.data而不是值:
<Input
value={ this.state.data }
ref={ item }
key={ i }
network={ item }
/>
我没有你完整的代码,但是我测试了它,它似乎是为我工作这条路。 (您可能需要将父数据的初始状态设置为空字符串或数据结构)
我认为_onChange中存在一个错误。它不应该是
_onChange(username) {
this.setState({ username: username });
},
这只是状态/值具有相同名称的快捷方式。 – jbr
是的。你是对的。还有一些问题,然后我看到了。 –
完整的代码在这里:https://github.com/statiks/statiks-react-native/blob/master/sources/input/index.js你也可以构建projet。无论如何,我无法访问'input.js'组件的'getInitialState'上的'this.props.value'。 – jbr
是的,您可能需要在父项的状态中将'value'的值设置为空字符串,直到数据准备就绪 –