我正在尝试将ReactDataGrid用于我的Web应用程序。但是我在渲染时仍然存在问题。我有Cluster
个对象要渲染。可以通过单击逐个选择群集,也可以使用select all
功能。当我单击全选按钮时,数据网格会平滑地呈现所有数据。然而,当我尝试逐个选择群集时,数据网格在数组的第二个对象之后开始render
。我试着看看console.log()
发生了什么。例如,当数组中有一个对象时,数组的长度打印为0.因此,每次都是-1。
这是群集对象。在这个对象下,我打印了它的长度。
console.log("this.props.ClusterPointsArray: ",this.props.ClusterPointsArray);
console.log("this.props.ClusterPointsArray.Length: ",this.props.ClusterPointsArray.length);
对象 - 数组关系有问题吗?我的意思是我应该将对象转换为数组吗?
请帮忙。
这是ClusterDetailGrid
组件文件。
import React, {Component} from 'react';
import ReactDataGrid from 'react-data-grid';
import {mapArrayReselect, ConnectComponent} from 'flightsuit';
import moment from 'moment';
import _ from 'lodash';
export default ConnectComponent(class ClusterDetailGrid extends Component {
state = {
isClusterDetailActive: false,
};
static mapState2Props(state) {
return {
activeTenant: state.tenant.activeTenant,
activeRoutesStopList: state.route.activeRoutesStopList,
activeClusters: state.ClusterProfile.activeClusters,
selectedClusters: state.ClusterProfile.selectedClusters,
ClusterPointsArray: state.ClusterProfile.ClusterPointsArray,
ClusterPoints: state.ClusterProfile.ClusterPoints,
profilesList: state.ClusterProfile.profilesList,
activeProfile: state.ClusterProfile.activeProfile
};
}
constructor(props) {
super(props);
this._columnss = [
{
key: 'ClusterName',
name: 'Cluster Name'
},
{
key: 'CustomerRefNo',
name: 'Customer Number'
},
{
key: 'CustomerName',
name: 'Customer Name'
}
];
}
componentWillMount() {
}
componentDidMount() {
}
componentWillUpdate(nextProps) {
this.createRows(nextProps.ClusterPointsArray);
}
createRows(Cluster) {
let rows = [];
for(let i = 0; i < Cluster.length; i++) {
for(let j = 0; j < Cluster[i].location.length; j++){
rows.push({
ClusterName: Cluster[i].Name,
CustomerRefNo: Cluster[i].location[j].Name,
CustomerName: Cluster[i].location[j].Description!=null?Cluster[i].location[j].Description:" "
});
}
}
this._rows = rows;
}
rowGetter(i) {
return this._rows[i];
}
render() {
console.log("this.props.ClusterPointsArray: ",this.props.ClusterPointsArray);
console.log("this.props.ClusterPointsArray.Length: ",this.props.ClusterPointsArray.length);
return (
this.props.ClusterPointsArray.length > 0 ?
<ReactDataGrid
columns={this._columnss}
rowGetter={this.rowGetter.bind(this)}
rowsCount={this._rows.length}
overScan={{
colsStart: 5,
colsEnd: 5,
rowsStart: 5,
rowsEnd: 25
}}
/>
:
<div>Your cluster details are loading...</div>
);
}
});