- 有人可以帮我解决这个问题吗?我收到此问题标题中描述的错误。我想将 JSON 数据放入 react-grid-layout 组件中。这个库可以在(https://github.com/STRML/react-grid-layout)上找到
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import Employee from './Employee';
import "./react-grid-layout/css/styles.css";
import "./react-resizable/css/styles.css"
var ReactGridLayout = require('react-grid-layout');
var data = [];
class MyFirstGrid extends React.Component {
constructor() {
super();
this.state = {
data: []
};
}
componentDidMount(){
fetch("http://localhost:8080/TrainingWebMvcSpring2/roottypes/listAll.do")
.then( (response) => {
return response.json() })
.then( (json) => {
this.setState({data: json});
});
}
render () {
console.log(data);
return (
<ReactGridLayout className="layout" cols={12} rowHeight={30} width={1200}>
{this.state.data.map(function(item, key){
return(
<div>
<div key="a" data-grid={{x: 0, y: 0, w: 1, h: 2, static: true}}> {item}</div>
<div key="b" data-grid={{x: 1, y: 0, w: 3, h: 2, minW: 2, maxW: 4}}> {item} </div>
<div key="c" data-grid={{x: 4, y: 0, w: 1, h: 2}}> {item} </div>
</div>
)
})}
</ReactGridLayout>
)
}
}
export default MyFirstGrid;