2

Hi This is my json value

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
          }
        ]
      }
    ]
  };
}

And Here I am using primereact datatable. And this is the code i am using to show my data in the table>

 <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>

And the value i get for this.state.sales[0].stdCtExamMarks is Image Here

But i need both (and so on) stdCtExamMarks values from the json data. How can i do it?

Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166
Aarif Hasan
  • 57
  • 1
  • 8

1 Answers1

0

But i need both (and so on) stdCtExamMarks values from the json data. How can i do it?

So you need to extract stdCtExamMarks from every object in the array? You can use a map to do this. It will return an array of mapped objects:

<DataTable value={this.state.sales.map(sale => sale.stdCtExamMarks)}>
Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166