2016-09-15 3 views
0

이것은 반품되는 내 텍스트 태그입니다. "abc"의 입력 값을 "123"또는 다른 문자열을 참조로 바꾸고 싶습니다. 편집() { this.refs.ref1 }텍스트 문자열을 변경하고 싶습니다.

<Text ref="ref1" onPress={this.edit.bind(this)}>abc</Text> 

당신은 무엇 onPress에이 상태에서 텍스트를 넣어 상태를 업데이트 할 수 있습니다 텍스트

답변

1

에서 문자열을 변경 편집 기능에서 사용할 수 있습니다, UI를 업데이트 할 반응하는 트리거 : 당신이 참조를 사용해야하는 경우

constructor(props) { 
super(props) 
this.state = {mytext:'abc'} 
} 

edit() { 
    this.setState({mytext:'123'}) 
} 

render() { 
    return <Text ref="ref1" onPress={this.edit.bind(this)}>{this.state.mytext}</Text> 
} 

, 다음 텍스트를 렌더링하는 구성 요소에 대한 참조를 넣어 동적 텍스트를 변경 this.ref1.setState({mytext:'something'})를 호출합니다.

관련 문제