反应网格布局与数据网传下来的子组件无法正常工作

问题描述 投票:0回答:2

我想实现与阵营网格布局作出反应可调整大小的组件。我打得四处那么一点点了解它是如何工作的,然后在我的项目安装了它,但我似乎无法得到它的工作为我的孩子组件甚至不用类反应并网项目。

我使用的数据网格,以网格道具传递给我的孩子组成。我看不到我在做什么错。

import React, {Component} from 'react';
import ChartHolder from '../components/charts/chart-holder';
import RGL, { WidthProvider } from "react-grid-layout";

const ReactGridLayout = WidthProvider(RGL);

class TabContent extends Component {
    constructor(props){
        super(props);
    }


    handleChartResize = (layout) => {
        console.log('this is the layout', layout);
    }

    render(){
        let tabsChartData = this.props.tabsData.currentActiveTabData[0].data;
        let chartData = tabsChartData.map((data, index)=>{
            return(
            <ChartHolder
                key={`${this.props.tabsData.currentActiveTabData[0].tab.id}_${index}`}
                id={index}
                position={data.position}
            />);
        });
        return (
                <div
                    className="tab-content"
                >
                    <ReactGridLayout
                        cols={2}
                        rowHeight={450}
                        width={1000}
                        onLayoutChange={this.handleChartResize}
                        isDraggable={false}
                        isResizeable={true}
                    >
                        {chartData}
                    </ReactGridLayout>
                </div>
            );
    }
}

这是chartHolder成分,我添加数据网格:

import React, {Component} from 'react';
import {css} from 'react-emotion';
import GridLoader from '../spinners/grid-loader';
import Plot from 'react-plotly.js';
import _ from 'lodash';
import Chart from './Chart';
import styled from 'styled-components';

const ChartChildGrid = styled.div`
    background-color: white;
    padding: 5px;
    margin: 5px;
`;

class ChartHolder extends Component {
    render() {
        return(
            <ChartChildGrid
                index={this.props.id}
                draggable={true}
                onDragStart={this.handleDragStart}
                onDragEnd={this.handleDragEnd}
                onDragOver={this.handleDragOver}
                onDragLeave={this.handleDragLeave}
                onDrop={this.handleDragDrop}
                data-grid={this.props.position}
            >
                <div 
                    className="chart-holder-header"
                >
                    <span
                        onClick={()=>this.props.handleRemoveChart(this.props.id)}
                        className="close-tab"
                    > 
                            &times;
                    </span>
                </div>
                <div className="chart-holder-body" >
                    {_.isEmpty(this.props.data) && <GridLoader/>}
                    {
                        !_.isEmpty(this.props.data) && 
                        <Chart
                            data={this.props.data}
                            width={this.props.width}
                        />
                    }
                </div>
            </ChartChildGrid>
        );
    }
}

export default ChartHolder;

我已经删除了代码的最专有部分,但如预期,这是不工作,因为我不能调整chartHolder组件,它甚至没有像cssTransforms任何类和反应调整大小像我在例子中看到。它确实如我所料安慰正确的布局,但似乎并没有被改变大小。

javascript reactjs react-grid-layout
2个回答
0
投票

我设法得到它的工作。在任何情况下,正面临着同样的挑战,这个问题是因为某种原因发生反应并网布局不接受定制组件。你必须将其套在一个div。

https://github.com/STRML/react-grid-layout/issues/576上面的链接帮助我发现这个问题。


0
投票

实际上,你可以使用自定义组件,但你要了一些必要的道具传递给它。这是在解决问题#299

内部网格布局的使用您的自定义组件是这样的...

<GridLayout>
    <div key="1">...</div>
    <div key="2">...</div>
    <CustomComponent key="3" />
</GridLayout>

里面你customComponent的需要作出以下道具。

<div {...this.props} className={this.props.className}>
    content goes here...
</div>

Code Sample

© www.soinside.com 2019 - 2024. All rights reserved.