我在平面列表中創(chuàng)建了一個(gè)按鈕,當(dāng)用戶(hù)單擊一個(gè)特定項(xiàng)目時(shí),它的按鈕應(yīng)該改變狀態(tài)并且應(yīng)該出現(xiàn)遞增按鈕,但是按鈕會(huì)改變所有項(xiàng)目的狀態(tài)。我也通過(guò)了 id 但它不起作用,有人可以幫助我......下面是我的代碼項(xiàng)目.js<FlatList data={this.props.items} extraData={this.props} keyExtractor={(items) => items.id.toString()} numColumns={2} renderItem={({ item }) => ( <CardBuyItem> <Image style={styles.image} source={item.image} /> <View style={styles.detailContainer}> <Text style={styles.title}>{item.title}</Text> <Text style={styles.subTitle} numberOfLines={1}> {item.subTitle} </Text> <Text style={styles.price}>Rs {item.price}</Text> </View> {this.props.button && this.props.added.length > 0 ? ( <View style={styles.add}> <Text style={styles.quantity}>{item.quantity}</Text> <MaterialCommunityIcons style={styles.iconUp} size={20} name="plus-circle-outline" onPress={() => this.props.addQuantity(item.id)} /> <MaterialCommunityIcons style={styles.iconDown} size={20} name="minus-circle-outline" onPress={() => this.props.subtractQuantity(item.id)} /> </View> ) : ( <View style={styles.buy}> <Text style={styles.buyonce} onPress={() => { this.props.addToCart(item.id); this.props.showCart(); this.props.showButton(item.id); }}
React Native,所有項(xiàng)目的狀態(tài)都在變化,而不是被點(diǎn)擊的項(xiàng)目
胡子哥哥
2023-05-19 15:01:26