2015-11-03 59 views
0

enter image description here如何使用使用Key的作爲Colomn頭Handsontable

我試圖用colomn頭以動手錶的數據發送到服務器以JSON格式鍵的鍵值對,我得到的輸出作爲發送JSON數據

[ 「羅希特」, 「庫納爾」, 「DDD」, 「DDD」]

,但我想作爲

{ 
"SourceIP" : "172.34.32.43,172.23.34.56", 
"DestinationIP":"172.34.32.43,123.345.432.345", 
"Port": "8080", 
"Protocol":"TCP" 
} 

什麼需要輸出改變使代碼爲ou TPUT這樣

我的代碼:

jQuery(document).ready(function(){ 



    var container = document.querySelector('#exampleGrid'); 

    var hot = new Handsontable(container, { 

     startRows: 1, 
     startCols: 5, 
     minSpareCols: 0, 
     //always keep at least 1 spare row at the right 
     minSpareRows: 0, 
     //always keep at least 1 spare row at the bottom, 
     colHeaders: ['Source Ip','Destination Ip','Port','Protocol','Issue'], 
     rowHeaders: true, 
     //colHeaders: true, 
     contextMenu: true, 
     persistentState: true, 
     manualColumnResize: true, 
     manualRowResize: true[![enter image description here][1]][1] 
    }); 

Handsontable.Dom.addEvent(load, 'click', function() { 





     console.log(JSON.stringify({hot.getData()})); 
    }); 

回答

2

你想做的事在初始化的對象實際上是定義一個data結構是什麼。現在你甚至沒有定義任何東西(甚至可能會破壞東西)。所以,你應該做這樣的事情:

data: [] 

,然後定義您的columns對象:

columns: [ 
    {data:'SourceIP'}, 
    {data:'DestinationIP'}, 
    {data:'Port'}, 
    {data:'Protocol'} 
] 

這定義了列的順序,以及如何創建對象。如果您現在執行hot.getData(),它會作爲對象返回。

+0

如何合併Handsontable中的單元格 – Labeo

+0

這是一個完整的其他問題,請繼續並將其作爲自己的問題。 – ZekeDroid

+0

http://stackoverflow.com/questions/33539972/how-to-make-data-from-a-merged-cell-to-be-applied-for-all-the-cells-in-merged-re – Labeo

相關問題