diff --git a/js/display.js b/js/display.js index 93d4c7c..bf55fd9 100755 --- a/js/display.js +++ b/js/display.js @@ -14,23 +14,27 @@ $.getJSON('./config.json', function(config){ // get data from remote $.getJSON(config['remote'], function(source){ - // alert(source[sourceId]['image_url']); - - // add image_url to the DOM - $('#img').prepend(''); - - // add links to CORE and BASE to read_more - var encodedName = encodeURI(source[sourceId]['name']); - $('#read_more').prepend('Continue reading about this source in CORE and BASE.'); - - // create a view only form with alpaca - $('#form').alpaca({ - "schemaSource": "./schemas/schema.json", - "optionsSource": "./schemas/options.json", - "data" : source[sourceId], - "view" : "bootstrap-display-horizontal" + // Find the item with the matching "id" + var selectedSource = source.find(item => item.id === sourceId); + + if (selectedSource) { + // add image_url to the DOM + $('#img').prepend(''); + + // add links to CORE and BASE to read_more + var encodedName = encodeURI(selectedSource['name']); + $('#read_more').prepend('Continue reading about this source in CORE and BASE.'); + + // create a view-only form with alpaca using the selected source data + $('#form').alpaca({ + "schemaSource": "./schemas/schema.json", + "optionsSource": "./schemas/options.json", + "data" : selectedSource, + "view" : "bootstrap-display-horizontal" }); - + } else { + // Handle the case where no matching "id" is found + console.log("Source with id '" + sourceId + "' not found."); + } }); - });