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

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

使用拼接函數(shù)時(shí),如何在數(shù)組中移動(dòng)javascript整個(gè)對(duì)象?(反應(yīng).js)

使用拼接函數(shù)時(shí),如何在數(shù)組中移動(dòng)javascript整個(gè)對(duì)象?(反應(yīng).js)

侃侃無極 2022-08-04 16:21:01
我正在 React 中使用拖放交互.js。我正在使用拼接函數(shù)對(duì)“行”數(shù)組進(jìn)行重新排序,該函數(shù)在拖動(dòng)完成后使用下面的 onDragEnd 函數(shù)調(diào)用:onDragEnd = (result) => {    const { destination, source, draggableId, type } = result;    if (!destination) {        return;    }    if (        destination.draggableId === source.droppableId &&        destination.index === source.index    ) {        return;    }    if (type === "row") {        const newRowOrder = Array.from(**this.state.currentRows**);        newRowOrder.splice(source.index, 1);        newRowOrder.splice(destination.index, 0, **draggableId**);        const newState = {            ...this.state,            currentRows: newRowOrder,        };        this.setState(newState);    }};在 onDragEnd 函數(shù)稱為 currentRow 狀態(tài)之前,如下所示:currentRow 狀態(tài)在 onDragEnd 之前當(dāng)調(diào)用該函數(shù)時(shí),拼接函數(shù)起作用(我認(rèn)為),但它不會(huì)移動(dòng)數(shù)組中的整個(gè)對(duì)象,而只是移動(dòng)ID。拼接函數(shù)中使用的拖動(dòng) Id 是需要移動(dòng)的對(duì)象的 ID。在 onDragEnd 函數(shù)被調(diào)用后,currentRow 狀態(tài)如下所示:currentRow 狀態(tài)在 onDragEnd 之后是否可以將整個(gè)對(duì)象移動(dòng)到新索引?
查看完整描述

1 回答

?
搖曳的薔薇

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

我認(rèn)為您只是插入dragableId,您可以使用該函數(shù)找到整個(gè)對(duì)象并插入整個(gè)對(duì)象newRowOrder.splice(destination.index, 0, **draggableId**);Array.find


onDragEnd = (result) => {

    const { destination, source, draggableId, type } = result;

    if (!destination) {

        return;

    }

    if (

        destination.draggableId === source.droppableId &&

        destination.index === source.index

    ) {

        return;

    }


    if (type === "row") {

        const draggableRow = this.state.currentRows.find(row => row.id === draggableId);

        const newRowOrder = Array.from(this.state.currentRows);

        newRowOrder.splice(source.index, 1);

        newRowOrder.splice(destination.index, 0, draggableRow);


        const newState = {

            ...this.state,

            currentRows: newRowOrder,

        };


        this.setState(newState);

    }

}


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

添加回答

舉報(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)