最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

react拖拽組件react-sortable-hoc的使用

 更新時間:2023年02月24日 09:34:54   作者:小菜鳥飛飛飛~  
本文主要介紹了react拖拽組件react-sortable-hoc的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

使用react-sortable-hoc實現(xiàn)拖拽

如圖:

在這里插入圖片描述

提示:下面案例可供參考

1.文件1

代碼如下(示例):文件名稱:./dragcomponents

import * as React from 'react'
import {
    sortableContainer,
    sortableElement,
    sortableHandle,
} from "react-sortable-hoc"; // 拖拽的關鍵組件

const Sortable: React.FC<any> = (props) => {
    const { dataSource = [], ComSortItem, sortEnd } = props;
    // 拖拽時原列表替換
    function arrayMoveMutable(array, fromIndex, toIndex) {
        const startIndex = fromIndex < 0 ? array.length + fromIndex : fromIndex;
        if (startIndex >= 0 && startIndex < array.length) {
            const endIndex = toIndex < 0 ? array.length + toIndex : toIndex;
            const [item] = array.splice(fromIndex, 1);
            array.splice(endIndex, 0, item);
        }
    }

    // 拖拽時返回新數(shù)組
    function arrayMoveImmutable(array, fromIndex, toIndex) {
        array = [...array];
        arrayMoveMutable(array, fromIndex, toIndex);
        return array;
    }

    // 拖拽容器
    const SortableContainer = sortableContainer(({ children }) => {
        return <div>{children}</div>;
    });

    // 拖拽ico
    const DragHandle = sortableHandle((value1, sortIndex1) => (
        <div id='ListItem' className='ListItem' >
            <div className="ChildCom">
                <ComSortItem data={value1} index={sortIndex1} updateData={updateData} />
            </div>
        </div>
    ));
    function handleDelete(index) {
        const List = [...dataSource];
        List.splice(index, 1)
        sortEnd(List);
    }
    // 數(shù)據(jù)更新
    function updateData(val, index) {
        const List = [...dataSource];

        List[index] = val;
        sortEnd(List);
    }
    // 拖拽體
    const SortableItem = sortableElement(({ value, sortIndex }) => {
        return (
            // <div id='ListItem' className='ListItem' >
            //     <DragHandle value1={value} sortIndex1={sortIndex} />
            // </div>
            <DragHandle valuedata={value} sortIndexdata={sortIndex} />
        );
    });

    // 拖拽后回調(diào)
    const onSortEnd = ({ oldIndex, newIndex }) => {
        const List = arrayMoveImmutable(dataSource, oldIndex, newIndex);
        sortEnd(List);
    };
    return (
        <>
            <SortableContainer onSortEnd={onSortEnd} useDragHandle helperClass="row-dragging-item">
                {dataSource.length > 0 &&
                    dataSource.map((value, index) => (
                        <SortableItem
                            key={`sortable-item-${index}`}
                            index={index}
                            value={value}
                            sortIndex={index}
                        />
                    ))}
            </SortableContainer>
        </>
    );
}

export default Sortable;

2.文件2

代碼如下(示例):文件名稱’./usedrag’

import * as React from 'react'
import { Checkbox } from 'antd'

import Sortable from './dragcomponents'
import './index.scss'
const _ = require('lodash')
import store from './store'
import { SAVE_RENDER_ALL_DATA } from './actionType'
const Usedrag: React.FC<any> = (props) => {
    const { state, dispatch } = React.useContext(store);
    // 自定義拖拽體
    const {upDateRenderData} = props
    const showdata ={...props.renderData}
    function AddForm(showdata) {
        return (
            < div className='ItemBox'>
                
                <div className='name'><span className="icon iconfont iconyidongshu"></span>{showdata.data.valuedata.fieldName}</div>
                <div className='Opt'>
                    <span>控件標簽顯示名稱<span>{showdata.data.valuedata.labelName}</span></span>
                    <span>所占列寬<span>{showdata.data.valuedata.span}</span></span>
                    {/* <Checkbox onChange={changeChecked} checked={checked} ></Checkbox> */}
                </div>
            </div>
        )
    }

    const updateSource = (val) => {
        const arrdata: any = _.cloneDeep(props.renderData)
        const arr: any = _.cloneDeep(val)
        if(JSON.stringify(arrdata) !== JSON.stringify(arr)){
            for (let i = 0; i <= arr.length - 1; i++) {
                arr[i].edit = 1;
            }
        }
        // upDateRenderData(arr)
        dispatch({
            type: SAVE_RENDER_ALL_DATA,
            value: arr
        })
    }

    return (
        <div className='RightBox' >
            <div className='item-con' style={{ overflow: 'auto' }}>
                <Sortable
                    className='sortable'
                    dataSource={...props.renderData}
                    ComSortItem={(p) => <AddForm {...p} />}
                    sortEnd={(val) => {
                        updateSource(val)
                    }}
                />
            </div>
        </div>
    );
};


export default Usedrag

3.使用

代碼如下(示例):

import Usedrag from './usedrag';
<Usedrag renderData={renderData}/>

到此這篇關于react拖拽組件react-sortable-hoc的使用的文章就介紹到這了,更多相關react拖拽組件react-sortable-hoc內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • React 高階組件入門介紹

    React 高階組件入門介紹

    本篇文章主要介紹了React高階組件入門介紹,這篇文章中我們詳細的介紹了什么是高階組件,如何使用高階組件,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • React + Threejs + Swiper 實現(xiàn)全景圖效果的完整代碼

    React + Threejs + Swiper 實現(xiàn)全景圖效果的完整代碼

    全景圖效果非常漂亮給人帶來極好的用戶體驗效果,那么基于前端開發(fā)如何實現(xiàn)這種效果呢,下面小編給大家?guī)砹薘eact + Threejs + Swiper 實現(xiàn)全景圖效果,感興趣的朋友一起看看吧
    2021-06-06
  • react-router4按需加載(踩坑填坑)

    react-router4按需加載(踩坑填坑)

    這篇文章主要介紹了react-router4按需加載(踩坑填坑),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • 詳解如何在React中有效地監(jiān)聽鍵盤事件

    詳解如何在React中有效地監(jiān)聽鍵盤事件

    React是一種流行的JavaScript庫,用于構建用戶界面,它提供了一種簡單而靈活的方式來創(chuàng)建交互式的Web應用程序,在React中,我們經(jīng)常需要監(jiān)聽用戶的鍵盤事件,以便根據(jù)用戶的輸入做出相應的反應,本文將向您介紹如何在React中有效地監(jiān)聽鍵盤事件,并展示一些常見的應用場景
    2023-11-11
  • 路由react-router-dom的基本使用教程

    路由react-router-dom的基本使用教程

    在React中,路由是一套映射規(guī)則,是URL路徑與組件的對應關系。使用React路由,就是配置路徑和組件的對應關系,這篇文章主要介紹了路由react-router-dom的使用,需要的朋友可以參考下
    2023-02-02
  • 解決React報錯Encountered?two?children?with?the?same?key

    解決React報錯Encountered?two?children?with?the?same?key

    這篇文章主要為大家介紹了React報錯Encountered?two?children?with?the?same?key解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-12-12
  • React?之最小堆min?heap圖文詳解

    React?之最小堆min?heap圖文詳解

    這篇文章主要為大家介紹了React?之最小堆min?heap圖文詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • React函數(shù)式組件Hook中的useState函數(shù)的詳細解析

    React函數(shù)式組件Hook中的useState函數(shù)的詳細解析

    Hook 就是 JavaScript 函數(shù),這個函數(shù)可以幫助你鉤入(hook into) React State以及生命周期等特性,這篇文章主要介紹了React Hook useState函數(shù)的詳細解析的相關資料,需要的朋友可以參考下
    2022-10-10
  • React組件設計模式之組合組件應用實例分析

    React組件設計模式之組合組件應用實例分析

    這篇文章主要介紹了React組件設計模式之組合組件,結合實例形式分析了React組件設計模式中組合組件相關概念、原理、應用場景與操作注意事項,需要的朋友可以參考下
    2020-04-04
  • React中的Context應用場景分析

    React中的Context應用場景分析

    這篇文章主要介紹了React中的Context應用場景分析,Context 提供了一種在組件之間共享數(shù)據(jù)的方式,而不必顯式地通過組件樹的逐層傳遞 props,通過實例代碼給大家介紹使用步驟,感興趣的朋友跟隨小編一起看看吧
    2021-06-06

最新評論

谢通门县| 宝丰县| 永康市| 惠安县| 班玛县| 九江市| 天柱县| 遵义县| 静乐县| 宿迁市| 丰顺县| 秦安县| 库伦旗| 兴和县| 衡水市| 唐山市| 昔阳县| 吉林市| 兴海县| 大洼县| 上饶市| 通城县| 白城市| 星子县| 姜堰市| 涿州市| 兴城市| 奇台县| 吴旗县| 新竹市| 荃湾区| 静宁县| 吉安市| 慈溪市| 阿勒泰市| 康乐县| 手机| 望都县| 大兴区| 林西县| 天全县|