Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React-Native:访问TextInput中的按键属性_React Native_Key_Textinput - Fatal编程技术网

React-Native:访问TextInput中的按键属性

React-Native:访问TextInput中的按键属性,react-native,key,textinput,React Native,Key,Textinput,我尝试访问TextInput中的密钥属性,以将其保存在状态中(然后保存在Redux中)。我在一个数组中创建了从第一个屏幕获得的大量文本输入字段: render() { const { playerAmount } = this.props; var textBoxes = []; for (var i = 0; i < playerAmount; i++) { var placeholderText = 'Player ' + (i + 1);

我尝试访问TextInput中的密钥属性,以将其保存在状态中(然后保存在Redux中)。我在一个数组中创建了从第一个屏幕获得的大量文本输入字段:

render() {
    const { playerAmount } = this.props;
    var textBoxes = [];
    for (var i = 0; i < playerAmount; i++) {
      var placeholderText = 'Player ' + (i + 1);
      textBoxes.push(
        <TextInput
          key = {i+1}
          onChangeText={(text) => {
            const Player = Object.assign({}, this.state.Player, { playerName: text, playerNumber: this.props.key});
            this.setState({ Player });
          }}
          placeholder={placeholderText}
          placeholderTextColor="grey"
        >
        </TextInput>

      );
正如你所看到的,我对本地人的反应是相当陌生的。你知道怎么解决这个问题吗

非常感谢!:)

为什么不这样做呢

render() {
  const { playerAmount } = this.props;
  var textBoxes = [];
  for (var i = 0; i < playerAmount; i++) {
    var placeholderText = 'Player ' + (i + 1);
    const key = i+1;
    textBoxes.push(
          <TextInput
              key = {key}
              onChangeText={(text) => {
                const Player = Object.assign({}, this.state.Player, { playerName: text, playerNumber: key});
                this.setState({ Player });
              }}
              placeholder={placeholderText}
              placeholderTextColor="grey"
          >
          </TextInput>
    );
  }
}
render(){
const{playerAmount}=this.props;
var textboxs=[];
对于(变量i=0;i
);
}
}
类Firebase扩展React.Component{
陈述={
名称:“”,
编号:'',
}
onChangeTextInput=key=>val=>{
this.setState({[key]:val})
}
render(){
返回(
)
}
}

非常感谢您!如果我将
key={I+1}
放入JSX元素,它为什么会这样工作?谢谢!:-)
render() {
  const { playerAmount } = this.props;
  var textBoxes = [];
  for (var i = 0; i < playerAmount; i++) {
    var placeholderText = 'Player ' + (i + 1);
    const key = i+1;
    textBoxes.push(
          <TextInput
              key = {key}
              onChangeText={(text) => {
                const Player = Object.assign({}, this.state.Player, { playerName: text, playerNumber: key});
                this.setState({ Player });
              }}
              placeholder={placeholderText}
              placeholderTextColor="grey"
          >
          </TextInput>
    );
  }
}
class Firebase extends React.Component{
  state={
    name:'',
    number:'',

  }
  onChangeTextInput = key => val => {
    this.setState({[key]:val})
  }
  render(){
    return(
      <View>
        <TextInput
        value={this.state.name}
        onChangeText={this.onChangeTextInput('name')}
        />
         <TextInput
        value={this.state.number}
        onChangeText={this.onChangeTextInput('number')}
        />
      </View>
    )
  }
}