rh.js
925 Bytes
/**
* Updates the options inside of a given HTML select tag from a SPARQL
* result set delivered by a SPIN template call.
* The template call must return the value as first column, and the
* display label as second column.
* @param id the ID of the select element, e.g. "#mySelect")
* @param template the URI of the template to call
* @param args an object with the argument to the template call
*/
function updateSelect(id, template, args) {
args['_template'] = template;
args['ajax'] = true;
$.getJSON("template", args, function(j) {
var vars = j['head'].vars;
var valueVar = vars[0];
var labelVar = vars[1];
var bindings = j['results'].bindings;
var options = '';
for (var i = 0; i < bindings.length; i++) {
var binding = bindings[i];
options += '<option value="' + binding[valueVar].value + '">' + binding[labelVar].value + '</option>';
}
$(id).html(options);
});
}