第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

React Native,所有項(xiàng)目的狀態(tài)都在變化,而不是被點(diǎn)擊的項(xiàng)目

React Native,所有項(xiàng)目的狀態(tài)都在變化,而不是被點(diǎn)擊的項(xiàng)目

胡子哥哥 2023-05-19 15:01:26
我在平面列表中創(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);                        }}
查看完整描述

1 回答

?
偶然的你

TA貢獻(xiàn)1841條經(jīng)驗(yàn) 獲得超3個(gè)贊

您有一個(gè)通用的狀態(tài)變量,這會(huì)導(dǎo)致它顯示所有按鈕。

你可以像這樣做一個(gè)簡(jiǎn)單的解決方案。在您的平面列表中,您可以有一個(gè)邏輯來(lái)顯示按鈕

{this.props.added.find(x=>x.id==item.id) !=null ? (

或者,如果您必須使用 reducer,則必須在數(shù)組中擁有一個(gè)屬性并更新它,這將是維護(hù)起來(lái)很復(fù)雜的。


查看完整回答
反對(duì) 回復(fù) 2023-05-19
  • 1 回答
  • 0 關(guān)注
  • 152 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)