react-native – setNativeProps文本组件的更改值React Native D
发布时间:2020-12-15 05:04:57 所属栏目:百科 来源:网络整理
导读:由于性能原因,我想直接更新组件的值. render(){ViewText style={styles.welcome} ref={component = this._text = component} Some Text/TextTouchableHighlight underlayColor='#88D4F5' style={styles.button} View Text style={styles.buttonText} onPress
由于性能原因,我想直接更新组件的值.
render(){ <View> <Text style={styles.welcome} ref={component => this._text = component}> Some Text </Text> <TouchableHighlight underlayColor='#88D4F5' style={styles.button}> <View> <Text style={styles.buttonText} onPress={this.useNativePropsToUpdate.bind(this)}> Iam the Child </Text> </View> </TouchableHighlight> </View> } 这是我用来更新文本组件的方法.我不知道我是否正在设置正确的属性/如何确定要设置的属性: useNativePropsToUpdate(){ this._text.setNativeProps({text: 'Updated using native props'}); } 本质上尝试遵循此示例中的相同方法: 编辑: this._text.props.children = "updated"; (我知道这是在RN中做事的正确方法).我收到错误“无法分配给对象’#’的只读属性’子” 所以也许这就是为什么它因某些原因无法在RN中更新的原因?
而不是试图改变< Text>的内容.零件.我刚刚替换为< TextInput editable = {false} defaultValue = {this.state.initValue} />并保持其余代码相同.如果有人知道如何更改< Text>的值使用setNativeProps或其他直接操作方法.发布答案,恶意审查并接受.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |