From 4a78b32b34fe3431ebb21f9d36903bceed9d062e Mon Sep 17 00:00:00 2001 From: j2blake Date: Thu, 27 Oct 2011 14:35:54 +0000 Subject: [PATCH] NIHVIVO-2343 Create a JavaScript utility for parsing the output of the SparqlQueryAjaxController. --- webapp/web/js/sparqlUtils.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 webapp/web/js/sparqlUtils.js diff --git a/webapp/web/js/sparqlUtils.js b/webapp/web/js/sparqlUtils.js new file mode 100644 index 000000000..d77a2403d --- /dev/null +++ b/webapp/web/js/sparqlUtils.js @@ -0,0 +1,22 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +/* + * Parse the results that we got from the SparqlQueryAjaxController. + * + * The input is a complex structure from the controller. The output is an array + * of maps where each map represents a result row, populated with key-value pairs. + */ +sparqlUtils = { + parseSparqlResults: function(data) { + var parsed = []; + $.each(data.results.bindings, function() { + var row = {}; + for (var i in this) { + row[i] = this[i].value; + } + parsed.push(row); + }); + return parsed; + } +}; +