@@ -1407,6 +1407,32 @@ class DataHarmonizer {
1407
1407
return false ;
1408
1408
}
1409
1409
1410
+ /**
1411
+ * Construct a dictionary of source field names pointing to column index
1412
+ * @param {Object } fields A flat version of data.js.
1413
+ * @return {Map<String, Integer> } Dictionary of all fields.
1414
+ */
1415
+ getFieldNameMap ( fields ) {
1416
+ const map = { } ;
1417
+ for ( const [ fieldIndex , field ] of fields . entries ( ) ) {
1418
+ map [ field . name ] = fieldIndex ;
1419
+ }
1420
+ return map ;
1421
+ }
1422
+
1423
+ /**
1424
+ * Construct a dictionary of source field TITLES pointing to column index
1425
+ * @param {Object } fields A flat version of data.js.
1426
+ * @return {Map<String, Integer> } Dictionary of all fields.
1427
+ */
1428
+ getFieldTitleMap ( fields ) {
1429
+ const map = { } ;
1430
+ for ( const [ fieldIndex , field ] of fields . entries ( ) ) {
1431
+ map [ field . title ] = fieldIndex ;
1432
+ }
1433
+ return map ;
1434
+ }
1435
+
1410
1436
/**
1411
1437
* Create a matrix containing the grid's headers. Empty strings are used to
1412
1438
* indicate merged cells.
@@ -2074,32 +2100,6 @@ class DataHarmonizer {
2074
2100
*
2075
2101
*/
2076
2102
2077
- /**
2078
- * Get a dictionary of source field names pointing to column index
2079
- * @param {Object } fields A flat version of data.js.
2080
- * @return {Dictionary<Integer> } Dictionary of all fields.
2081
- */
2082
- getFieldNameMap ( fields ) {
2083
- const map = { } ;
2084
- for ( const [ fieldIndex , field ] of fields . entries ( ) ) {
2085
- map [ field . name ] = fieldIndex ;
2086
- }
2087
- return map ;
2088
- }
2089
-
2090
- /**
2091
- * Get a dictionary of source field TITLES pointing to column index
2092
- * @param {Object } fields A flat version of data.js.
2093
- * @return {Dictionary<Integer> } Dictionary of all fields.
2094
- */
2095
- getFieldTitleMap ( fields ) {
2096
- const map = { } ;
2097
- for ( const [ fieldIndex , field ] of fields . entries ( ) ) {
2098
- map [ field . title ] = fieldIndex ;
2099
- }
2100
- return map ;
2101
- }
2102
-
2103
2103
/**
2104
2104
* Modifies exportHeaders map of fields so that each field contains an array
2105
2105
* of one or more source fields by name that are used to compose it.
@@ -2852,21 +2852,30 @@ class DataHarmonizer {
2852
2852
toJSON ( ) {
2853
2853
const handsontableInstance = this . hot ;
2854
2854
const tableData = this . fullData ( handsontableInstance ) ;
2855
- const columnHeaders = handsontableInstance . getColHeader ( ) . map ( stripDiv ) ;
2855
+ const columnHeaders = handsontableInstance . getColHeader ( ) . map ( stripDiv ) ; // TODO: use fields() or this.getFlatHeaders()[1];
2856
+ console . log ( columnHeaders ) ;
2856
2857
2857
2858
function createStruct ( row ) {
2858
2859
const structInstance = { } ;
2860
+ // iterate over the columns in a row
2859
2861
for ( let i = 0 ; i < row . length ; i ++ ) {
2862
+
2863
+ const columnHeader = columnHeaders [ i ] ;
2864
+ console . log ( columnHeader ) ;
2865
+
2860
2866
// Optional type checking (adjust data types as needed)
2861
- if ( typeof columnHeaders [ i ] === 'string' ) {
2862
- structInstance [ columnHeaders [ i ] ] = row [ i ] ;
2863
- } else if ( typeof columnHeaders [ i ] === 'number' ) {
2864
- structInstance [ columnHeaders [ i ] ] = Number ( row [ i ] ) ; // Convert to number
2867
+ if ( typeof columnHeader === 'string' ) {
2868
+ structInstance [ columnHeader ] = row [ i ] ;
2869
+ } else if ( typeof columnHeader === 'number' ) {
2870
+ structInstance [ columnHeader ] = Number ( row [ i ] ) ; // Convert to number
2865
2871
} else {
2866
2872
// Handle other data types if needed
2867
- structInstance [ columnHeaders [ i ] ] = row [ i ] ;
2873
+ structInstance [ columnHeader ] = row [ i ] ;
2868
2874
}
2869
2875
}
2876
+
2877
+ console . log ( structInstance ) ;
2878
+
2870
2879
return structInstance ;
2871
2880
}
2872
2881
@@ -2880,6 +2889,8 @@ class DataHarmonizer {
2880
2889
}
2881
2890
}
2882
2891
2892
+ console . log ( arrayOfStructs ) ;
2893
+
2883
2894
return arrayOfStructs ;
2884
2895
}
2885
2896
}
0 commit comments