Is it an asynchronous problem that the access request data cannot be accessed?

problem description

getModelVersion () backend request data

Parameter limit

getCurrentData has only one parameter record

related codes

  getCurrentData = (record) => {
    const { searchParams } = this.state;
    const params = {
      status: searchParams.status,
      modelId: record.id,
    };
    getModelVersion(params).then((result) => { //
      if (result.length > 1) {
        return "";
      } else {
        return styles.disabledRow;
      }
    });
  }

Table in render

<Table
   className={styles.subTable}
   dataSource={this.state.SampleData}
   ....
   ....
   expandedRowKeys={expandedRowKeys}
   onExpandedRowsChange={this.onExpandedRowsChange}
   rowClassName={(record) => { return this.getCurrentData(record); }} // 
/>

what is the result?

getCurrentData returns undefined

Jun.02,2021

add a return and try

clipboard.png

Update

getCurrentData = (record) => {
    ...
    return Promise.resolve({}).then(=>{
        return getModelVersion(params) =>{
        .......
        }
    })
    ...
}

there should be something wrong with the getModelVersion method. Check whether this method is correct


the asynchronous bar


should not be used here.

use ES7 async await syntax.

  getCurrentData = async (record) => {
    const { searchParams } = this.state;
    const params = {
      status: searchParams.status,
      modelId: record.id,
    };
    const result = await getModelVersion(params);
    if (result.length > 1) {
        return '';
      } else {
        return styles.disabledRow;
      }
  }

1. Confirm whether the network request is sent
2. Show the getModelVersion code

.
Menu