React Native - Flatlist Single Select

后端 未结 1 1343
北海茫月
北海茫月 2021-01-28 21:52

I\'ve been searching around how to make a single select in Flatlist but I can\'t find any, here in my code I\'am trying to make a single select on every cells t

相关标签:
1条回答
  • 2021-01-28 22:32

    The TextInputs are targeting the same state SplOrder so, if you change it in any TextInput the others will display the same. The solution I see is to put an state for each item you create. You should do this:

                        <TextInput
                            placeholder = "Insert Special Request"
                            onChangeText = { (text) => this.setState({ ['SplOrder'+index]: text }) }
                            value = { this.state['SplOrder'+index] }
                        />
    

    The second problem we have discussed in the comments should be fixed by passing index parameter to incrementCount function.

    Hi, now in the method _incrementCount() you will have to pass the index and increment each count with it index as you have in the value of. So you could do

    <TouchableOpacity
        onPress = {() => this._incrementCount(index)}>
        <Text> + </Text>
    </TouchableOpacity>
    

    And then change your _incrementCount method adding a parameter and doing like this:

    _incrementCount(index) {
        this.setState({ ['count'+index]: this.state['count'+index] + 1 });
    }
    
    0 讨论(0)
提交回复
热议问题