未捕获的类型错误:无法读取未定义的属性(读取“绑定”)

发布于 2025-01-10 03:10:32 字数 4436 浏览 0 评论 0原文

我正在尝试开发能够拖动多个 div 并将其组合为一个(其中的内容)并将其放入另一列的功能。在尝试这样做时,我进行了功能检查,该检查基本上确定应该更改哪个 div 以及它是否被合并。我在我的州设置值时收到此错误。我尝试了几种方法,但它以某种方式显示了这个错误。这将作为道具传递给另一个子组件。可以请他找出问题所在。

提前致谢。

输入图片此处描述

在此处输入图像描述


const finalValueUpdate = (
  finalValue, 
  task, 
  column, 
  selectedTaskIds, 
  tasks) => {
  if (finalValue === false && column.id == 'done') {
    console.log('check1');
    this.setState({ bigFinalValue: task.word }).bind(this);
  }
  else if(
    column.id == 'done' && 
    selectedTaskIds.length > 1 && 
    typeof bigFinalValue !== 'undefined') {
    console.log('check2');
    tasks.map((task, index) => {
      if(selectedTaskIds.includes(task.id)) {
        this.bigFinalValue += task.word + ' ';
        }
      })
  }

}

export default class Column extends Component<Props> {
  state = {
    selectedTaskIds: this.props.selectedTaskIds,
    finalValue: this.props.finalValue,
    bigFinalValue: '',
  };


  componentDidUpdate(prevProps: Props) {
    if (prevProps.selectedTaskIds !== this.props.selectedTaskIds) {
      this.setState({ selectedTaskIds: this.props.selectedTaskIds });
    }
  };


  render() {
    const column = this.props.column;
    const tasks = this.props.tasks;
    const selectedTaskIds = this.props.selectedTaskIds;
    const draggingTaskId = this.props.draggingTaskId;
    const finalValue = this.props.finalValue;
    
    return (
      <Container>
        <Title>{column.title}</Title>
        <Droppable droppableId={column.id} isCombineEnabled={true}>
          {(provided, snapshot) => (
            <TaskList
              ref={provided.innerRef}
              isDraggingOver={snapshot.isDraggingOver}
              {...provided.droppableProps}
            >
              {tasks.map((task, index) => {
                const isSelected = Boolean(
                  getSelectedMap(selectedTaskIds)[task.id]
                );
                const isGhosting =
                  isSelected &&
                  Boolean(draggingTaskId) &&
                  draggingTaskId !== task.id;
                

                if (finalValue === false && column.id == 'done') {
                  console.log('check1');
                  this.setState({ bigFinalValue: task.word }).bind(this);
                  console.log(this.state.bigFinalValue);
                }
                else if(
                  column.id == 'done' && 
                  selectedTaskIds.length > 1 && 
                  typeof bigFinalValue !== 'undefined') {
                  console.log('check2');
                  tasks.map((task, index) => {
                    if(selectedTaskIds.includes(task.id)) {
                      this.bigFinalValue += task.word + ' ';
                      }
                    })
                } 

                console.log("selectedTaskIds", selectedTaskIds);
                console.log('finalValue', finalValue);
                console.log('bigFinalValue', this.bigFinalValue);
                // for the console log of data incoming from the server
                console.log("==>", tasks);

                return (
                  <Task
                    task={task}
                    columnId = {this.props.column.id}
                    index={index}
                    key={task.id}
                    selectedTaskArray = {tasks}
                    finalValue = {finalValue}
                    isSelected={isSelected}
                    isGhosting={isGhosting}
                    selectionCount={selectedTaskIds.length}
                    selectedTaskIds={selectedTaskIds}
                    bigFinalValue = {this.bigFinalValue}
                    toggleSelection={this.props.toggleSelection}
                    toggleSelectionInGroup={this.props.toggleSelectionInGroup}
                    multiSelectTo={this.props.multiSelectTo}
                  />
                );
              })}
              {provided.placeholder}
            </TaskList>
          )}
        </Droppable>
      </Container>
    );
  }
}

I am trying to work on functionality that will be able to drag multiple divs and combine it is as one (the contents in it) and drop it into the other column. In trying to do so I put a functionality check which is identifying basically which div should be changed and whether it gets merged or not. I am getting this error while setting the value in my state. I try a few ways but it's somehow showing this error. This will be passed as a prop to another child component. Can please him in identifying the problem.

Thanks in advance.

enter image description here

enter image description here


const finalValueUpdate = (
  finalValue, 
  task, 
  column, 
  selectedTaskIds, 
  tasks) => {
  if (finalValue === false && column.id == 'done') {
    console.log('check1');
    this.setState({ bigFinalValue: task.word }).bind(this);
  }
  else if(
    column.id == 'done' && 
    selectedTaskIds.length > 1 && 
    typeof bigFinalValue !== 'undefined') {
    console.log('check2');
    tasks.map((task, index) => {
      if(selectedTaskIds.includes(task.id)) {
        this.bigFinalValue += task.word + ' ';
        }
      })
  }

}

export default class Column extends Component<Props> {
  state = {
    selectedTaskIds: this.props.selectedTaskIds,
    finalValue: this.props.finalValue,
    bigFinalValue: '',
  };


  componentDidUpdate(prevProps: Props) {
    if (prevProps.selectedTaskIds !== this.props.selectedTaskIds) {
      this.setState({ selectedTaskIds: this.props.selectedTaskIds });
    }
  };


  render() {
    const column = this.props.column;
    const tasks = this.props.tasks;
    const selectedTaskIds = this.props.selectedTaskIds;
    const draggingTaskId = this.props.draggingTaskId;
    const finalValue = this.props.finalValue;
    
    return (
      <Container>
        <Title>{column.title}</Title>
        <Droppable droppableId={column.id} isCombineEnabled={true}>
          {(provided, snapshot) => (
            <TaskList
              ref={provided.innerRef}
              isDraggingOver={snapshot.isDraggingOver}
              {...provided.droppableProps}
            >
              {tasks.map((task, index) => {
                const isSelected = Boolean(
                  getSelectedMap(selectedTaskIds)[task.id]
                );
                const isGhosting =
                  isSelected &&
                  Boolean(draggingTaskId) &&
                  draggingTaskId !== task.id;
                

                if (finalValue === false && column.id == 'done') {
                  console.log('check1');
                  this.setState({ bigFinalValue: task.word }).bind(this);
                  console.log(this.state.bigFinalValue);
                }
                else if(
                  column.id == 'done' && 
                  selectedTaskIds.length > 1 && 
                  typeof bigFinalValue !== 'undefined') {
                  console.log('check2');
                  tasks.map((task, index) => {
                    if(selectedTaskIds.includes(task.id)) {
                      this.bigFinalValue += task.word + ' ';
                      }
                    })
                } 

                console.log("selectedTaskIds", selectedTaskIds);
                console.log('finalValue', finalValue);
                console.log('bigFinalValue', this.bigFinalValue);
                // for the console log of data incoming from the server
                console.log("==>", tasks);

                return (
                  <Task
                    task={task}
                    columnId = {this.props.column.id}
                    index={index}
                    key={task.id}
                    selectedTaskArray = {tasks}
                    finalValue = {finalValue}
                    isSelected={isSelected}
                    isGhosting={isGhosting}
                    selectionCount={selectedTaskIds.length}
                    selectedTaskIds={selectedTaskIds}
                    bigFinalValue = {this.bigFinalValue}
                    toggleSelection={this.props.toggleSelection}
                    toggleSelectionInGroup={this.props.toggleSelectionInGroup}
                    multiSelectTo={this.props.multiSelectTo}
                  />
                );
              })}
              {provided.placeholder}
            </TaskList>
          )}
        </Droppable>
      </Container>
    );
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我最亲爱的 2025-01-17 03:10:32

我不擅长类组件,我建议您使用功能组件,它可能会解决您的问题,但我认为问题是这一行

this.setState({ bigFinalValue: task.word }).bind(this);

我不知道为什么它会抛出此错误,但尝试使用功能组件并更新状态在 useEffect 挂钩中。

I'm not good with class components and I suggest you use the functional component and it might fix your problem but I think the problem is this line

this.setState({ bigFinalValue: task.word }).bind(this);

I don't know why it throws this error but try using a functional component and update the state in a useEffect hook.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文