0

I used a table component of Ant Design Pro. Now I care about the contents of the nested subtable. The code is as follows

const expandedRowRender = () => {
  const data = [];
  for (let i = 0; i < 3; i += 1) {
    data.push({
      key: i,
      date: '2014-12-24 23:12:00',
      name: 'This is production name',
      upgradeNum: 'Upgraded: 56',
    });
  }
  return (
    <ProTable
      columns={[
        { title: 'Date', dataIndex: 'date', key: 'date' },
        { title: 'Name', dataIndex: 'name', key: 'name' },

        { title: 'Upgrade Status', dataIndex: 'upgradeNum', key: 'upgradeNum' },
        {
          title: 'Action',
          dataIndex: 'operation',
          key: 'operation',
          valueType: 'option',
          render: () => [<a key="Pause">Pause</a>, <a key="Stop">Stop</a>],
        },
      ]}
      headerTitle={false}
      search={false}
      options={false}
      dataSource={data}
      pagination={false}
    />
  );
};

I tried to modify the data on the original basis, this can achieve the effect

const expandedRowRender = () => {
  const data: any = [];

  data[0] = {key: 1, 'param_name':'999', 'var_type':'int', 'var_name':'paraone', 'var_value':100};
  data[1] = {key: 2, param_name:'777', var_type:'int', var_name:'paraone', var_value:100};
  console.log(data)
  return (
    <ProTable
      columns={[
        { title: '参数名', dataIndex: 'param_name', key: 'param_name' },
        { title: '变量类型', dataIndex: 'var_type', key: 'var_type' },
        { title: '变量名', dataIndex: 'var_name', key: 'var_name' },
        { title: '变量值', dataIndex: 'var_value', key: 'var_value' },
      ]}
      headerTitle={false}
      search={false}
      options={false}
      dataSource={data}
      pagination={false}
    />
  );
};

Print out the data

Page rendering success

Then I use AXIos to get the data from the interface,but it doesn't render to the page

  request('/api/testdb', {
    method: 'get',
  }).then((res: any) => {
    res.param.map((item: object) => {
      data.push(item)
    })
  })

Print out the data

Page rendering failed

jason-lin
  • 35
  • 5
  • try to add `.catch(function (error)` after your `then()` during your `axios` call, read more about catching axios errors [this link](https://stackoverflow.com/questions/49967779/axios-handling-errors) – Omar Dieh Jun 13 '22 at 15:47
  • ``` request('/api/testdb', { method: 'get', }).then((res: any) => { res.param.map((item: object) => { data.push(item) }) }).catch(function(err: any) { console.error(err) }) ``` No error message is displayed – jason-lin Jun 13 '22 at 16:00
  • The problem is resolved and the data is retrieved from the component's resuest property – jason-lin Jun 14 '22 at 05:47

0 Answers0