Вам потребуется сопоставить авторов по имени и присоединиться к ним.
const formatAuthors = (authors) => {
return authors.map(author => author.person).join(', ') || '<em>None</em>';
};
Пример
Редактировать: Я добавил прослушиватель щелчков для записей, чтобы предупредить их идентификатор коллекции. Я добавил идентификатор для каждого элемента, используя атрибут данных.
const formatAuthors = (authors) => {
return authors.map(author => author.person).join(', ') || 'Anonymous';
};
$(() => {
const url = "https://data.azgs.arizona.edu/api/v1/metadata";
$('.destinations-form').on('submit', function(e) {
e.preventDefault();
let searchstring = $('input[type="text"]').val();
let requestUrl = url + `?text=${searchstring}&title=${searchstring}`;
$.ajax({
type: 'GET',
url: requestUrl,
success: function(res) {
let repo = res.data.map(item =>
`<div class="res-entry" data-collection-id="${item.collection_id}">
<div class="res-entry-title">${item.metadata.title}</div>
<div class="res-entry-author">${formatAuthors(item.metadata.authors)}</div>
<div class="res-entry-series">${item.metadata.series}</div>
<div class="res-entry-download">
<a href="${item.links[0].href}"><button>Download</button>
</div>
</div>`);
$("#results").empty().append(repo); // Empty previous...
}
});
});
$('.container').on('click', '.res-entry', e => {
// Make a follow-on query with this ID...
let collectionId = e.currentTarget.getAttribute('data-collection-id');
alert(`Collection ID = ${collectionId}`);
});
});
#results {
margin-top: 1em;
}
.res-entry {
border: thin solid grey;
margin: 0.667em;
padding: 0.5em;
}
.res-entry .res-entry-title {
font-size: 1em;
font-weight: bold;
margin-bottom: 0.5em;
}
.res-entry .res-entry-author {
font-size: 0.8em;
font-style: italic;
margin-bottom: 0.25em;
}
.res-entry .res-entry-author:before {
content: 'By: ';
}
.res-entry .res-entry-series {
font-size: 0.9em;
}
.res-entry .res-entry-download {
margin-top: 0.5em;
}
.res-entry .res-entry-download a {
display: block;
text-align: right; /* If you want it on the right */
}
.res-entry .res-entry-download a button {
border: thin solid grey;
background: #FFF;
}
.res-entry .res-entry-download a button:hover {
border: thin solid grey;
background: #EE7;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form class="destinations-form" role="search">
<div class="input-line">
<input id="searchForm" type="text" class="form-input check-value" placeholder="Search Documents" />
<button type="submit" class="form-submit btn btn-special">Search</button>
</div>
</form>
<section>
<div class="container">
<div class="row">
<div class="col-sm-12 col-xs-24">
<div class="boat-box">
<div id="results" action="search.html"></div>
</div>
</div>
</div>
</div>
</section>