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

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

根據(jù)數(shù)組索引更改圖像狀態(tài) - React.js

根據(jù)數(shù)組索引更改圖像狀態(tài) - React.js

慕虎7371278 2023-03-18 17:52:08
我有一系列帶有一些 svg 的卡片,需要根據(jù)點(diǎn)擊單獨(dú)(上下)更改狀態(tài)。模態(tài)由引導(dǎo)程序處理。所以,我試圖根據(jù)數(shù)組的索引更改 svg(硬編碼)的狀態(tài)。但是,即使我得到了 id(動(dòng)態(tài)的),每次我點(diǎn)擊 svg 箭頭時(shí),所有的 svg 都會(huì)改變狀態(tài)。我認(rèn)為狀態(tài)不應(yīng)該在 for 循環(huán)中改變,我想知道問題是否來自 {this.state.arrowShown && }。因此,如何只改變被點(diǎn)擊的卡片的svg狀態(tài),而不改變其他卡片的狀態(tài)呢?import Container from 'react-bootstrap/Container'import Card from 'react-bootstrap/Card'import Row from 'react-bootstrap/Row'import Col from 'react-bootstrap/Col'import { withTranslation } from 'react-i18next';import Accordion from 'react-bootstrap/Accordion'import Button from 'react-bootstrap/Button'class ProjectCard extends React.Component {    constructor() {        super();        this.state = {            arrowShown: true,            arrowHidden: false,        }        this.handleClick = this.handleClick.bind(this);    }    handleClick(event, index) {        const id = event.currentTarget.id;        const projectArr = this.props.projects;        console.log("this.props.porjects", this.props.projects)        for (var i = 0; i < projectArr.length; i++) {            console.log("projectArr[i].idP1", projectArr[i].idP2)            if (projectArr[i].idP2 === id) {                console.log("same same")                this.setState({                    arrowShown: !this.state.arrowShown,                    arrowHidden: !this.state.arrowHidden                })                // newState[projectArr[i].idP2.arrowShown] = projectArr[i].idP2 === projectArr[i].idP2            }        }        //     // this.setState(newState)        // }    }
查看完整描述

1 回答

?
qq_遁去的一_1

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

你在這里改變每張圖片的狀態(tài)



this.setState({

        arrowShown: !this.state.arrowShown,

        arrowHidden: !this.state.arrowHidden

    })


并顯示具有相同狀態(tài)值的每個(gè)圖像。這就是為什么每次翻轉(zhuǎn)一個(gè)圖像時(shí)所有圖像都會(huì)被翻轉(zhuǎn)的原因。


你能做的就是保持這樣的狀態(tài)



       this.state = {  

           [index1] : { arrowShown : true , arrowHidden :false }  ,

           [index2] : { arrowShown : true , arrowHidden :false }  ,

       //and so on

       }


然后每當(dāng)基于點(diǎn)擊圖像的索引時(shí),您只更新該特定索引的狀態(tài),就像這樣......



       this.setState({[indexOfTheClickedImage ] : { 

                arrowShown: !this.state.[indexOfTheClickedImage].arrowShown ,

                arrowHidden: !this.state.[indexOfTheClickedImage].arrowHidden

       }}


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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