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

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

為什么setstate在選擇項(xiàng)后的react js中不起作用?

為什么setstate在選擇項(xiàng)后的react js中不起作用?

藍(lán)山帝景 2021-10-14 10:10:16
我的setState功能無(wú)法正常工作,因?yàn)樗鼪](méi)有呈現(xiàn)組件。設(shè)置重現(xiàn)。選擇任何區(qū)域。示例見(jiàn)下圖第一行第二列。查看控制臺(tái)上的更新行數(shù)據(jù)?,F(xiàn)在我正在嘗試使用更新的數(shù)據(jù)更新視圖,但它沒(méi)有反映。這是我的代碼 https://codesandbox.io/s/rdg-cell-editing-4cu5p如果onUpdate: args => {            const { startCell, topLeft, bottomRight } = args;            const { idx: topLeftColumn, rowIdx: topLeftRowIdx } = topLeft;            const { idx: startColumn, rowIdx: startRowIndex } = startCell;            const { idx: bottomColumn, rowIdx: bottomRowIndex } = bottomRight;            const rows = this.state.rows.slice();            console.log(this.state.rows[startRowIndex][keys[startColumn]]);            let item = this.state.rows[startRowIndex][keys[startColumn]];            console.log(topLeftRowIdx, "topLeftRowIdx");            console.log(bottomRowIndex, "bottomRowIndex");            console.log(topLeftColumn, "topLeftColumn");            console.log(bottomColumn, "bottomColumn");            for (var i = topLeftRowIdx; i <= bottomRowIndex; i++) {              for (var j = topLeftColumn; j <= bottomColumn; j++) {                console.log("----");                rows[i][keys[j]] = item;              }            }            console.log(rows);            this.setState({              rows: [...rows]            });            //  this.setState({            //   rows:[            //     { id: 0, title: "Task 1ssss", complete: "Task 2" },            //     { id: 1, title: "Task 2", complete: "Task 3" },            //     { id: 2, title: "Task 3", complete: "Task 4" }            //   ]            //  });            console.log(this.state);            return rows;          },如果我做硬編碼setState,這是注釋掉的代碼,那么它就可以工作//  this.setState({            //   rows:[            //     { id: 0, title: "Task 1ssss", complete: "Task 2" },            //     { id: 1, title: "Task 2", complete: "Task 3" },            //     { id: 2, title: "Task 3", complete: "Task 4" }            //   ]            //  });上面的代碼在選擇區(qū)域后工作,當(dāng)我取消注釋代碼時(shí)它會(huì)更新視圖
查看完整描述

1 回答

?
慕仙森

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

改為數(shù)組深拷貝:



 this.setState({

              rows: [...rows]

        });


   this.setState({

      rows: JSON.parse(JSON.stringify(rows))

    });

在循環(huán)中復(fù)制項(xiàng)目的更有效方法:


 for (var i = topLeftRowIdx; i <= bottomRowIndex; i++) {

              for (var j = topLeftColumn; j <= bottomColumn; j++) {

                console.log("----");

                rows[i][keys[j]] = item;

              }

              rows[i] = { ...rows[i]};

            }


查看完整回答
反對(duì) 回復(fù) 2021-10-14
  • 1 回答
  • 0 關(guān)注
  • 296 瀏覽
慕課專(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)