Add more logic
This commit is contained in:
parent
8a1836418e
commit
833517b2dd
19
js/pis.js
19
js/pis.js
@ -9,7 +9,7 @@ async function findByOrigDest() {
|
|||||||
if (json == false) {
|
if (json == false) {
|
||||||
await noData()
|
await noData()
|
||||||
} else {
|
} else {
|
||||||
await displayData(json)
|
await insertData(json)
|
||||||
}
|
}
|
||||||
document.getElementById('crs-box').style = 'display:none'
|
document.getElementById('crs-box').style = 'display:none'
|
||||||
document.getElementById('result-box').style = 'display:block'
|
document.getElementById('result-box').style = 'display:block'
|
||||||
@ -22,23 +22,24 @@ async function fetchOrigDest() {
|
|||||||
return {origin: orig, destination: dest}
|
return {origin: orig, destination: dest}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function displayData(json) {
|
async function insertData(json) {
|
||||||
// Receives the JSON Respose ([{},{}]) containing one or more possible
|
// Receives the JSON Respose ([{},{}]) containing one or more possible
|
||||||
// PIS codes. Display the code and the stops with a method of scrolling between them.
|
// PIS codes. Display the code and the stops with a method of scrolling between them.
|
||||||
// Maybe as a table or a carousel?
|
// Maybe as a table or a carousel?
|
||||||
const div = document.getElementById('result-box')
|
const div = document.getElementById('result-box')
|
||||||
const tableHtml = `<table id="result-table">
|
const tableHtml = `<table id="result-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="code">Code</th>
|
<th class="code">Code</th>
|
||||||
<th class="stops">Stations</th>
|
<th class="stops">Stations</th>
|
||||||
</tr>
|
</tr>
|
||||||
</table>`
|
</table>`
|
||||||
div.insertAdjacentHTML("beforeend", tableHtml)
|
div.insertAdjacentHTML("beforeend", tableHtml)
|
||||||
const table = document.getElementById('result-table')
|
const table = document.getElementById('result-table')
|
||||||
const data = JSON.parse(json)
|
const data = JSON.parse(json)
|
||||||
for(var i = 0; i < data.length; i++) {
|
for(var i = 0; i < data.length; i++) { // Break into separate function. Need to
|
||||||
|
// iterate over stops.
|
||||||
let row = `<tr><td class="code">${data[i][code]}</td>
|
let row = `<tr><td class="code">${data[i][code]}</td>
|
||||||
<td class="stops">${data[i][stops]}</td></tr>`
|
<td class="stops">${data[i][stops]}</td></tr>`
|
||||||
table.insertAdjacentHTML("beforeend", row)
|
table.insertAdjacentHTML("beforeend", row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user