简体   繁体   English

React Typescript: Ant 设计表重新渲染特定列

[英]React Typescript: Ant Design Table Rerender specific Column

Im mutating my datasource State "this.state.question" but the Table Column "Actions" dont rerender.我正在改变我的datasource State "this.state.question"但表格列"Actions"不会重新呈现。

if (this.state.responseMessage.successful) {
   var index = this.state.question.findIndex(item => item.no == data.item1.no);
   this.state.question[index].group = data.item1.group;
   this.state.question[index].deactivated = data.item1.deactivated;
   this.state.question[index].information = data.item1.information;
}

Column that should change:应该改变的列:

{ title: "Actions", render: (record: ModelClass) => {
   return (
      <Space>
         <Button
            type="primary"
            disabled={record.deactivated} //<- nothing happens
         />
      </Space >
   )
}},

Never mutate state.切勿突变 state。

Quick glance tells me your code should look something like this:快速浏览告诉我你的代码应该是这样的:

if (this.state.responseMessage.successful) {
   this.setState(currentState => ({
      ...currentState,
      question: currentState.question.map((q) => {
        if(q.no !== data.item1.no) return q;
        return {
           ...q,
           ...data.item1
        }
      })
   }))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM