简体   繁体   English

Reactjs Material Table Tree模式在添加行数据时挂起

[英]Reactjs Material Table Tree mode hangs when row data are added

within my Reactjs app , i'am using material-table widget inside my component :在我的 Reactjs 应用程序中,我在我的组件中使用材料表小部件:

render() {使成为() {

return (
  <div>
    <Row>
      <MaterialTable
        title="Mon équipement"
        style={{ width: "100%", margin: "0%" }}
        localization={this.localization}
        columns={this.state.columns}
        data={this.state.equipments}
        options={{
          headerStyle: { borderBottomColor: 'cornflowerblue', borderBottomWidth: '3px', fontFamily: 'verdana' },
          actionsColumnIndex: -1,
          exportButton: true,
          draggable: true,
          grouping: false
        }}
        editable={{
          onRowUpdate: (newData, oldData) =>
            new Promise((resolve) => {
              this.handleRowUpdate(newData, oldData, resolve);
            }),
          onRowAdd: (newData) =>
            new Promise((resolve) => {
              this.handleRowAdd(newData, resolve)
            }),
          onRowDelete: (oldData) =>
            new Promise((resolve) => {
              this.handleRowDelete(oldData, resolve)
            }),
        }}
        parentChildData={(row, rows) => rows.find(item => item.id === row.parentId)}
      />
    </Row>
  </div>
);

} }

As you can see , i'm setting up my tree Mode within this line :如您所见,我在这一行中设置了我的树模式:

    parentChildData={(row, rows) => rows.find(item => item.id === row.parentId)}

The problem , that when adding a new row data问题,当添加新的行数据时

I ve this error我有这个错误

RangeError: Maximum call stack size exceeded DataManager.parentChildData [as parentFunc] RangeError:超过最大调用堆栈大小 DataManager.parentChildData [as parentFunc]

在此处输入图像描述

Suggestions ?建议?

I ran into a similar issue but it was because my table was in a reusable component and some of the data passed to that component didn't have a tree structure (ie no id and parentId properties) so the table was failing to render for those.我遇到了类似的问题,但这是因为我的表位于可重用组件中,并且传递给该组件的某些数据没有树结构(即没有idparentId属性),因此表无法为那些呈现. I added props to check if the data passed to the component was expected to have a tree structure and that seems to have resolved the issue for me:我添加了道具来检查传递给组件的数据是否应该具有树结构,这似乎已经解决了我的问题:

parentChildData={props.hasParentChildData? (row:any, rows:any) => rows.find((a:any) => a.id === row.parentId) : null}

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

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