React-Native獲取文本框的值


要想獲取文本框的值,首先我們需要看一下官方文檔的解釋:

這里的意思是說當文本框的內容改變的時候,文本框的輸入的內容就會作為一個參數進行傳遞。因此我們就可以獲取到文本框里面的內容就好了。

 1   constructor (props) {
 2     super (props)
 3     this.state = {
 4       screen: this.initScreen(),
 5       txtValue: null,
 6       dataSource: new ListView.DataSource({
 7         rowHasChanged: (row1, row2) => row1 !== row2
 8       }),
 9       loaded: false
10     }
11   }
12 
13 。。。。
14 
15 
16  <TextInput
17    selectTextOnFocus = {true}
18    onChangeText={(text) => {
19    this.state.txtValue = text
20    this.getContent()
21    }}
22 
23 。。。
24 
25 getContent () {
26     ToastAndroid.show(this.state.txtValue, ToastAndroid.LONG)
27   }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM