From 28ebae4525f35672acd6253b3022bdb8cdc1cbd1 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Wed, 28 Feb 2018 21:32:48 +0000 Subject: Update readme. Fix result parsing bug. Rearrange files - Prefix query result fields with an underscore to avoid clashing with JS builtin property/function names which causes issues with Tabulator - Move html files into their own dir --- editor-instance.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'editor-instance.js') diff --git a/editor-instance.js b/editor-instance.js index 8ed6674..6e2fd67 100644 --- a/editor-instance.js +++ b/editor-instance.js @@ -188,7 +188,7 @@ function handleResult(results) { dataTable = $("#result-table").tabulator({ height: "100%", columns: _mapColumnProperties(results), - data: results.rows + data: _escapeRowFieldNames(results.rows) }); _setExecutionStatusIndicator("OK"); @@ -198,12 +198,27 @@ function handleResult(results) { function _mapColumnProperties(results) { return results.fields.map((column) => { return { - field: column.name, + field: "_" + column.name, // "_" to match up to the output of _escapeRowFieldNames() title: column.name }; }); } +/** + * Return the row object with all fields prefixed with an underscore. + * This avoids issues with Tabulator which doesn't like fields to have the same identifiers + * as built in JS properties/functions (e.g. 'length') + */ +function _escapeRowFieldNames(rows) { + return rows.map(row => { + let escapedRow = {} + Object.keys(row).forEach(key => { + escapedRow["_" + key] = row[key]; + }); + return escapedRow; + }); +} + function _resultTable() { return $("#result-table"); } -- cgit v1.2.3