Как изменить формат данных в реакции HandsonTable - PullRequest
0 голосов
/ 05 февраля 2019

Я использовал реакцию handsonTable для ввода нескольких строк,

Я могу отправить запрос в следующем формате:

enter image description here

    this.state = {
        financialsettings: {
                colHeaders:['Service Item', 'Description Of Charges', 'Currency', 'Amount', 'Exchange Rate', 'Quantity', 'Exclusive GST', 'GST Rate', 'GST Amount', 'Total Inclusive GST', 'Vendor Name', 'Vendor Cost', 'Item Profit', 'Item Profit Percentage'],
                data: [{serviceItemId: "",description:"", currency:"", amount: "", exRate: "", quantity: "", amountExclusiveGst: "", gst: "", gstAmount: "", amountInclGst: "", vendorName : "", vendorCost: "", itemProfit: "", itemProfitPercentage: ""}],
                columns: [
                    { data:"serviceItemId",type: 'dropdown', source:[] },
                    { data:"description"},
                    { data: "currency"},
                    { data:"amount", type: 'numeric'},
                    { data:"exRate", type: 'numeric'},
                    { data:"quantity", type: 'numeric'},
                    { data:"amountExclusiveGst", readOnly: true},
                    { data:"gst", type: 'numeric'},
                    { data:"gstAmount", readOnly: true},
                    { data:"amountInclGst", readOnly: true},
                    { data:"vendorName"},
                    { data:"vendorCost"},
                    {data:"itemProfit", readOnly: true},
                    {data:"itemProfitPercentage", readOnly: true}

                ],



              },
   }

  <div className="col-md-12">
            <HotTable root="hot" ref="hot" settings={this.state.financialsettings} width="100%" strechH="all" />
         </div>



         Let data = {
          quotationItems: this.state.financialsettings.data,
         }

Но мне нужен формат в другом формате, как показано ниже

       financialsettings: {

          data: [{serviceItemId: "",
                    fields:[
                    {
                        "fieldName":"description",
                        "fieldDataType":"String",
                        "fieldValue":""
                    },
                    {
                        "fieldName":"currency",
                        "fieldDataType":"String",
                        "fieldValue":""
                    },
                   ]

                }],
          columns: [
              { data:"serviceItemId",type: 'dropdown', source:[] },
              { data:"description"},
              { data: "currency"},
              { data:"amount", type: 'numeric'},
              { data:"exRate", type: 'numeric'},
              { data:"quantity", type: 'numeric'},
              { data:"amountExclusiveGst", readOnly: true},
              { data:"gst", type: 'numeric'},
              { data:"gstAmount", readOnly: true},
              { data:"amountInclGst", readOnly: true},
              { data:"vendorName"},
              { data:"vendorCost"},
              {data:"itemProfit", readOnly: true},
              {data:"itemProfitPercentage", readOnly: true}

          ],

Когда я попробовал выше, значения формата не заполняются в поле Массив, а ключи со значениями только приходят.

Как изменить формат

I want this format instead of all the keys in the object  I need all the keys and its related value in the fields Array

...