如何在React HandsonTable中更改数据格式

时间:2019-02-05 10:52:56

标签: javascript angularjs reactjs handsontable

我正在使用react 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

0 个答案:

没有答案