reactjs - react-grid layout html不更新cols
问题描述
我使用反应网格布局:https ://github.com/react-grid-layout/react-grid-layout
我不明白为什么我的表格中的列数没有通过网络浏览器更新。
事实上,this.props.cols.lg 不是 17 就是 24。
当它是 17 时,我的表正确显示。另一方面,当我选择一个有 24 列的时间段时,我的列从第 18 列开始依次排列。
this.props.cols.lg 设置为正确的值(17 或 24),但我的 HTML 页面没有更新到设计级别。
这是单行上的正确表格:
如您所见,firefox web 控制台显示 react 属性与 17 一致:
和坏桌子
在这里,firefox web 控制台再次显示反应属性是正确的 (24),但没有被 web 浏览器应用:
重要信息,
this.props.cols.lg=loopValue+1; **contains the right value (17 or 24) but apply on 17**
预先感谢您的帮助。
这是我的代码的一部分:
import React, { useState, useEffect, Fragment } from 'react';
import { WidthProvider, Responsive } from "react-grid-layout";
import ReactTooltip from 'react-tooltip';
import _ from "lodash";
import { Button, Container } from 'react-bootstrap';
const ResponsiveReactGridLayout = WidthProvider(Responsive);
import { Responsive as ResponsiveGridLayout } from 'react-grid-layout';
/**
* This layout demonstrates how to use a grid with a dynamic number of elements.
*/
export class AddRemoveLayout extends React.PureComponent {
//les propriétés par défaut
static defaultProps = {
className: "layout border-darken-1 child-background-color",
cols:
{ lg: 10, md: 10, sm: 10, xs: 10, xxs: 10 },
width: 1000,
margin: [0, 0],
preventCollision: true,
autoSize: true,
// preventCollision: true,
rowHeight: 70,
// Build HTML to insert
render() {
//Week
let createDateItem =
(x, y, day) => ({
i: `date-${x}_${y}`,
x,
y,
w: 1,
h: 1,
myText: `${day}` ,
static: true
});
/**
*
* @param {*} y
* @param {*} xStart
* @param {num semaine} dateStart
* @param {nombre semaine total} count
*/
let getDateItems =
(y, xStart, dateStart, count,dateEnd) => {
let items = [];
let loopValue = 0;
while(dateStart<=dateEnd){//semainee
if(loopValue>1){
dateStart.setDate(dateStart.getDate() + 7)
}
if(dateStart<=dateEnd){
items.push(
createDateItem(xStart + loopValue, y, loopValue === 0 ? 0 :
(dateStart.getDate()+"/" +(dateStart.getUTCMonth()+1)+ " (Sem. "+loopValue +") ")
))
}
loopValue++;
}
console.log('props:')
console.log(this.props);
this.props.cols.lg=loopValue+1;
this.props.cols.md=loopValue+1;
this.props.cols.sm=loopValue+1;
this.props.cols.xs=loopValue+1;
this.props.cols.xxsloopValue+1;
console.log(this.props);
// console.log(AddRemoveLayout.defaultProps)
return items;
}
;
解决方案
我们找到了解决方案:
data: { idHoraire: 1 },
它总是发送到 PHP 的同一个项目,使用这段代码,我对我的 cols 有很好的显示,因为我要么发送 1 (17 cols) 要么 2 (25 cols) :
data: { idHoraire: url === "index2" ?2 : 1, },
推荐阅读
- c# - ASP.NET Core web.config requestFiltering 不覆盖 applicationhost.config
- blockchain - 将 ERC20 代币与其他 ERC20 代币交换
- mysql - 如何通过 Active Record Query Interface 编写 sql 请求并连接两个表,其中条件 - ids 数组
- c - 为什么第二个 malloc 在这种情况下会失败?
- gherkin - 有没有办法在 Gherkin 功能或场景描述中转义关键字?
- swift - Swift:如何在 Userdefaults 中保存和加载包含结构值的字典
- java - Java 生菜反应模式 - 捕获错误?
- python - 处理大小为 10**6 的列表的时间复杂度
- regex - 查找重复标记的子字符串
- java - java-如何多重(无限期)异步回调。有设计模式还是什么?