【问题标题】:reactjs - Inserting data into tables with propsreactjs - 使用道具将数据插入表中
【发布时间】:2020-08-18 08:52:28
【问题描述】:

我正在使用 reactjs。我正在使用 devextreme-reactive 可编辑表组件。

当我想将收到的 json 数据作为 arrayList 与 this.props.customer.customerDebts.customerAllDebts 添加到表中时出现错误,如下所示。

我该如何解决这个问题?

https://ibb.co/zrXmz9m

 <Paper style={{width: "100%"}}>
        <Grid
          rows={this.props.customerDebts.customerAllDebts.json}
          columns={this.state.columns}
        >
          <EditingState
            onCommitChanges={this.commitChanges}
            columnExtensions={[
              {columnName: "first_name", editingEnabled:false},
              {columnName: "last_name", editingEnabled:false},
            ]}
          />
          <PagingState
            defaultPageSize={5}
            defaultCurrentPage={5}
          />
          <IntegratedPaging />
          <Table />
          <TableColumnResizing
            defaultColumnWidths={this.state.defaultColumnWidths}
          />
          <TableHeaderRow />
          <PagingPanel
            pageSizes={this.state.pageSizes}
            messages={this.pagingPanelMessages}
          />
          <TableEditRow />
          <TableEditColumn
            showAddCommand
            showEditCommand
            showDeleteCommand
            commandComponent={Command}
          />
          <TableBandHeader
            columnBands={this.state.columnBands}
          />
        </Grid>
      </Paper>

【问题讨论】:

  • 错误是什么?
  • 我收到了图片中的错误,我无法导入 this.props.customerDebts.customerAllDebts 中的数据,它给出了错误。
  • 请帮帮我。

标签: reactjs react-props devextreme


【解决方案1】:

你所要做的就是当且仅当数据的长度大于0时有条件地渲染它。

<Paper style={{width: "100%"}}>
{ 
  this.props.customerDebts.customerAllDebts.customerAllDebts.length > 0 &&
  <Grid
  rows={ this.props.customerDebts.customerAllDebts.customerAllDebts }
  columns={this.state.columns}>
}
  <EditingState
    onCommitChanges={this.commitChanges}
    columnExtensions={[
      {columnName: "first_name", editingEnabled:false},
      {columnName: "last_name", editingEnabled:false},
    ]}
  />

【讨论】:

  • 我分享了所有代码,因为我遇到了错误。你能再编辑一下吗
  • 能否请您在这里分享代码沙箱链接,这样我可以清楚地了解您为什么会收到错误消息?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-17
相关资源
最近更新 更多