【问题标题】:Updating dhtmlx-sheduler uisng React使用 React 更新 dhtmlx-scheduler
【发布时间】:2020-07-06 17:04:39
【问题描述】:

我使用调度器如下:

从下拉列表(react-select)中,我选择了一个名称(我必须在调度程序上显示其事件)并且它显示正确,

nextState.showData 是一个数据数组。

window.scheduler.parse(nextState.showData, 'json')

但是当我取消选择相同的名称时,调度程序应该更新并且不显示任何事件,但调度程序不会更新(并且仍然显示现在取消选择的名称的事件)

虽然,在取消选择名称时,nextState.showData=[]

请帮忙。我正在使用 dhtmlx-scheduler 和 React........

【问题讨论】:

    标签: reactjs dhtmlx-scheduler


    【解决方案1】:

    这样,我解决了问题

    componentDidUpdate(prevProps) {
        if(this.props.showData.length===0) {
            window.scheduler.clearAll();
            window.scheduler.parse([], 'json')
        }
        else {
            window.scheduler.clearAll();
            window.scheduler.parse(this.props.showData, 'json')
        }
    }
    

    我没有在 shouldComponentUpdate() 中解析数据,而是在 componentDidUpdate() 中解析,它解决了我的问题

    礼貌 https://forum.dhtmlx.com/t/gantt-not-re-rendering-after-update/37702/2

    【讨论】:

      【解决方案2】:

      是的,主要思想是你应该在parse()新数据集之前每次调用scheduler.clearAll()

      您可以删除 if 条件中的 window.scheduler.parse([], 'json'),因为该行在代码中没有任何作用。

      用下一种方式改变你的代码是有意义的:

      componentDidUpdate(prevProps) {
          window.scheduler.clearAll();
          if(this.props.showData.length) {
              window.scheduler.parse(this.props.showData, 'json')
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2018-02-14
        • 2020-06-11
        • 2020-06-25
        • 2020-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-03
        • 1970-01-01
        相关资源
        最近更新 更多