Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find Items by ID and not by position #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions js/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<img src="'+source[sourceId]['image_url']+'" width="200px"/>');

// add links to CORE and BASE to read_more
var encodedName = encodeURI(source[sourceId]['name']);
$('#read_more').prepend('Continue reading about this source in <a href="https://core.ac.uk/search?q='+encodedName+'">CORE</a> and <a href="https://www.base-search.net/Search/Results?lookfor='+encodedName+'">BASE</a>.');

// 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('<img src="'+selectedSource['image_url']+'" width="200px"/>');

// add links to CORE and BASE to read_more
var encodedName = encodeURI(selectedSource['name']);
$('#read_more').prepend('Continue reading about this source in <a href="https://core.ac.uk/search?q='+encodedName+'">CORE</a> and <a href="https://www.base-search.net/Search/Results?lookfor='+encodedName+'">BASE</a>.');

// 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.");
}
});

});