This commit is contained in:
20
index.js
20
index.js
@@ -1,8 +1,24 @@
|
||||
const cheerio = require("cheerio");
|
||||
const mustache = require("./js/mustache.4.1.0.js");
|
||||
const fs = require("fs");
|
||||
const stores = require("./stores.json");
|
||||
|
||||
function TableViewTemplate(rows) {
|
||||
table = "<table>";
|
||||
rows.forEach((row, key) => {
|
||||
row.rowNumber = key;
|
||||
table = table + TableRowTemplate(row);
|
||||
});
|
||||
return table + "</table>";
|
||||
}
|
||||
|
||||
function TableRowTemplate({ rowNumber, name, address, city }) {
|
||||
return `
|
||||
<tr id="${rowNumber}" class="spotRow">
|
||||
<td class="name">${name}</td>
|
||||
<td>${address}, ${city}</td>
|
||||
</tr>`;
|
||||
}
|
||||
|
||||
fs.readFile("./index.html", function (err, data) {
|
||||
if (err) {
|
||||
throw err;
|
||||
@@ -15,7 +31,7 @@ fs.readFile("./index.html", function (err, data) {
|
||||
return aname === bname ? 0 : +(aname > bname) || -1;
|
||||
});
|
||||
|
||||
$("#Stores").html(mustache.render($("#Table").html(), { rows: stores }));
|
||||
$("#Stores").html(TableViewTemplate(stores));
|
||||
$("#storeCount").html(stores.length);
|
||||
$("#updatedOn").html(
|
||||
new Date().toLocaleDateString("en-US", {
|
||||
|
Reference in New Issue
Block a user