2

嗨,这是我的 json 值

constructor() {
  super();
  this.exportpdf = this.exportpdf.bind(this);
  this.state = {
    sales: [
      {
        customStudentId: "2064517",
        studentRoll: 26,
        studentName: "Md. Faiaz Jakir ",
        stdCtExamMarks: [
          {
            viewSerial: 1,
            subjectName: "Bangla ",
            subjectFullMark: 25,
            obtainedMark: 0,
            highestMarks: 25
          }
        ]
      },
      {
        customStudentId: "2065817",
        studentRoll: 27,
        studentName: "Miraj  Bin Atik ",
        stdCtExamMarks: [
          {
            viewSerial: 1,
            subjectName: "English ",
            subjectFullMark: 25,
            obtainedMark: 0,
            highestMarks: 25
          }
        ]
      }
    ]
  };
}

在这里,我使用的是 primereact 数据表。这是我用来在表格中显示我的数据的代码>

 <DataTable value={this.state.sales[0].stdCtExamMarks}>
        <Column field="subjectName" header="Subject" />
        <Column field="subjectFullMark" header="Full Mark" />
        <Column field="obtainedMark" header="Obtainedn Mark" />
        <Column field="highestMarks" header="Highest Mark" />
    </DataTable>

我得到的价值this.state.sales[0].stdCtExamMarksImage Here

但我需要来自 json 数据的两个(等等)stdCtExamMarks 值。我该怎么做?

4

1 回答 1

0

但我需要来自 json 数据的两个(等等)stdCtExamMarks 值。我该怎么做?

所以你需要stdCtExamMarks从数组中的每个对象中提取?您可以使用 amap来执行此操作。它将返回一个映射对象数组:

<DataTable value={this.state.sales.map(sale => sale.stdCtExamMarks)}>
于 2018-05-20T08:11:49.123 回答