Answer the question
In order to leave comments, you need to log in
How to parse 2 JSON files?
I am using InfiniteAjaxScroll in my project. The project - parses some JSON.
I want to combine certain elements from both JSONs by one common field, I know how to do this, but I can’t normally open the .json file for parsing in JS. I tried to open it with various methods and return it through return, but I got all sorts of obscure Promises and so on. I don’t rummage in js, more in php, but the task needs to be completed in js.
function nextHandler(pageIndex) {
return fetch('csgomarket.php').then(response => response.json()).then((data) => {
let frag = document.createDocumentFragment();
let itemsPerPage = 15;
let totalPages = Math.ceil(data.length / itemsPerPage);
let offset = pageIndex * itemsPerPage;
// walk over the movie items for the current page and add them to the fragment
for (let i = offset, len = offset + itemsPerPage; i < len; i++) {
const movie = data[i];
/* Здесь открытие файла api.json и добавление к массиву movie 3 элементов из файла api.json */
let item = createMovieItem(movie);
frag.appendChild(item);
}
let hasNextPage = pageIndex < totalPages - 1;
return this.append(Array.from(frag.childNodes)).then(() => hasNextPage);
// indicate that there is a next page to load
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question