2015-11-26 41 views

回答

0

做裁判使用的,可以作为参考作用的成分组件

例如:

<View> 
<TextInput style={styles.textInput} 
      ref={'usrname'} 
      placeholder={'Username'} 
      placeholderTextColor={'red'} 
      onChangeText={(userName) => this.setState({userName})} 
      value={this.state.userName} /> 
<TouchableOpacity onPress={this._onPressButton}> 
       <View style={styles.buttonContainer}> 
       <Text> Submit </Text> 
       </View> 
      </TouchableOpacity> 
</View> 

和onPress:

_onPressButton: function(e){ 
    var x = this.state.userName; 
    alert(x); //we can also use alert(this.state.userName) 
    }, 
+0

谢谢... @Pramod Mg但我怎么能在我的java代码中使用它?我可以将它传递给我的模块吗?像Mymodule._module.func(x); – JA21

+0

y到javacode>? –

+1

原因我想在我的java中使用我的CustomView .. 查看canvasView = findViewById(R.id.CustomView); 洙,我可以捕捉到我的CustomView里面的东西,问题是react-native没有xml,我知道它非常容易,如果它有一个xml文件,我可以说.. findViewById()... – JA21

1

这可以通过React.findNodeHandle完成。

在你的情况,

... 

var { findNodeHandle } = React; 

... 

render: function() { 
    return (
    <View> 
     <CustomView ref="customView"> 
     ... 
     </CustomView> 
    </View> 
); 
}, 

somethingLikeComponentDidMount: function() { 
    var customViewNativeID = findNodeHandle(this.refs.customView); 
    // Something else... 
} 

... 

可能做的工作。

有关工作示例(本机绑定两个组件),请检出here作为JS部分,here作为本机Java部分。