From 93de04e9b6eb85f44317157d21fe945b2a6ca2c3 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sat, 22 Apr 2023 22:44:32 +0100 Subject: [PATCH] Remove repeated DOM inserts --- js/pis.js | 13 ++++++++----- pis.html | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/js/pis.js b/js/pis.js index dd7ffca..c539fdb 100644 --- a/js/pis.js +++ b/js/pis.js @@ -27,21 +27,24 @@ async function insertData(json) { // PIS codes. Display the code and the stops with a method of scrolling between them. // Maybe as a table or a carousel? const div = document.getElementById('result-box') - const tableHtml = ` + let tableData = `
- -
Code Stations
` + ` div.insertAdjacentHTML("beforeend", tableHtml) const table = document.getElementById('result-table') const data = JSON.parse(json) + let results = 0 for(var i = 0; i < data.length; i++) { // Break into separate function. Need to // iterate over stops. - let row = `${data[i][code]} + tableData += `${data[i][code]} ${data[i][stops]}` - table.insertAdjacentHTML("beforeend", row) + results++ } + tableData += "" + table.insertAdjacentHTML("beforeend", tableData) + document.getElementById('result-count').textContent = results } async function noData() { diff --git a/pis.html b/pis.html index 2af8dbd..0b04c0b 100644 --- a/pis.html +++ b/pis.html @@ -55,7 +55,7 @@
-

Results

+

Results: 0