サンプルプロジェクトを実行しています。私のプロジェクトでは、私はlistViewを使用しています。上向き矢印ボタンをクリックして値を増やし、下向き矢印ボタンをクリックすると値が減少します。これら2つのボタンのいずれかをクリックすると、listViewのすべての行で値が変更されます。 listViewの特定の行だけの値を変更する方法。私に何か提案してください。ここで反応ネイティブを使用したlistViewのrowidに基づく増減値
は私のコードです:ここでは
class Example extends Component {
constructor(props){
super(props);
this.state={
dataSource: new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}),
count:1,
}
}
incrementFunc(rowID:number, listItems){
this.setState({
count : this.state.count + 1
},()=>{
this.setState({
dataSource:new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}).cloneWithRows(array)
})
})
}
decrementFunc(rowID:number,listItems){
this.setState({
count : this.state.count- 1
},()=>{
if(this.state.count <= 1){
this.setState({
count : 1
})
}
},()=>{
this.setState({
dataSource:new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}).cloneWithRows(array)
})
})
}
listOfItems(listItems, sectionID:number, rowID:number){
return(
<View style = {styles.buttonContainer}>
<View style={styles.arrowsView}>
<TouchableOpacity onPress ={this.incrementFunc.bind(this, rowID, listItems)}>
<Image style={styles.arrowStyle} source={require('@images/up-arrow.png')} />
</TouchableOpacity>
</View>
<View style={styles.numberView}>
<Text style={{fontSize:15, color:'black'}}>{this.state.count}
</Text>
</View>
<View style={styles.arrowsView}>
<TouchableOpacity onPress ={this.decrementFunc.bind(this, rowID, listItems)}>
<Image style={styles.arrowStyle} source={require('@images/down-arrow.png')} />
</TouchableOpacity>
</View>
</View>
)
}
render(){
return(
<View style={styles.listview}>
<ListView
dataSource={this.state.dataSource}
renderRow={this.listOfItems.bind(this)}/>
</View>
);
}
}
あなたはすべてのアイテムに1つの状態を使用しています。あなたはその状態を減らしています。それはすべてに影響しています。 –
何ですか?あなたはこれを説明できます – Lavaraju