如何添加10个文本输入并获得总数。 这是我的代码 10个文本输入可以是+值或 - 值
我只需要总和
export default class App extends React.Component {
renderTextBox(number) {
let placeholder = 'GAME ' + number;
return (
<View style={styles.column} key="number">
<TextInput keyboardType="numeric" key="number" placeholder={placeholder} underlineColorAndroid="transparent" style={styles.TextInputStyleClass} />
</View>
);
}
render() {
let teamOneGames = [];
let teamTwoGames = [];
for (let i = 1; i <= 10; i++) {
teamOneGames.push(this.renderTextBox(i));
teamTwoGames.push(this.renderTextBox(i));
}
return (
<View style={{flexDirection: "row", height: "100%"}}>
<View style={{ flex: 1, justifyContent: "center", backgroundColor: "#6dc6ed"}}>
<Text>TEAM 1</Text>
<TextInput placeholder="ENTER NAME" underlineColorAndroid="transparent" style={styles.TextInputStyleClass} />
<TextInput placeholder="ENTER NAME" underlineColorAndroid="transparent" style={styles.TextInputStyleClass} />
{teamOneGames}
答案 0 :(得分:0)
您可以使用 onChangeText 方法为 TextInput 获取值。你对价值进行操作。 Checkout this link for more info.
示例:
<TextInput
style={Style.KEEPYOURSTYLE}
value={text}
onChangeText={(currentText) => {
// DO OPERATION ON currentText
}}
/>