【发布时间】:2018-10-07 23:38:07
【问题描述】:
我正在开发 ReactNative 移动应用。 WebApp 运行顺畅,一切正常。但是当我将所有内容传输到移动部分时,我在输入字段中输入文本时遇到错误。我做错了什么,我的错误是什么?这是我的代码:
import React from 'react';
import { StyleSheet, TextInput, View } from 'react-native';
export default class App extends React.Component {
state={
message:"Hi {name}, your rating for this app is {rating}"
}
handleName=()=>{
this.setState({
message:"Hi "+this.refs.name.value+", your rating for this app is {rating}"
})
}
handleRating=()=>{
this.setState({
message:"Hi "+this.refs.name.value+", your rating for this app is "+this.refs.rating.value
})
}
render() {
return (
<View style={styles.container}>
<TextInput
placeholder="Your Name"
ref="name"
onChangeText={this.handleName}
/>
<TextInput
placeholder="Your Rating"
ref="rating"
onChangeText={this.handleRating}
/>
<View>{this.state.message}</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
【问题讨论】:
标签: reactjs react-native