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   }

 

posted @ 2016-01-20 10:55  weifengzz  阅读(5458)  评论(0编辑  收藏  举报