我想从状态中的对象分配一个值,而不将其绑定到状态。
<TextInput value={this.state.bigObject.sub.name}/>
<TextInput value={this.state.bigObject.sub.name.toString()}/> // also tried this
编辑文本框时,该值将恢复为状态中的值。我不想更新状态onChange
,而只想更新状态onSubmitEditing
。我该如何实现?
答案 0 :(得分:1)
使用setNativeProps直接操作TextInput。希望有帮助
<TextInput
ref={component => this._textInput = component}
style={{height: 50, width: 200, marginHorizontal: 20, borderWidth: 1, borderColor: '#ccc'}}
/>
this._textInput.setNativeProps({text: ''});