React native - 如何添加10个文本输入并获得总计

时间:2018-04-01 16:24:31

标签: javascript reactjs react-native

如何添加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}



    

1 个答案:

答案 0 :(得分:0)

您可以使用 onChangeText 方法为 TextInput 获取值。你对价值进行操作。 Checkout this link for more info.

示例:

               <TextInput
                    style={Style.KEEPYOURSTYLE}
                    value={text}
                    onChangeText={(currentText) => {
                        // DO OPERATION ON currentText
                    }}
                />