未捕获的类型错误:无法读取未定义的属性(读取“绑定”)
我正在尝试开发能够拖动多个 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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不擅长类组件,我建议您使用功能组件,它可能会解决您的问题,但我认为问题是这一行
我不知道为什么它会抛出此错误,但尝试使用功能组件并更新状态在 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
I don't know why it throws this error but try using a functional component and update the state in a useEffect hook.