BACKGROUND:
I am using taffyDB (http://taffydb.com/) with materializecss’ accordion function. The following JavaScript works: when I click on the id=show1970 accordion drawer, it opens and displays the content in the DB for partNo and partName in a table row. (My question is after the code.)
function show1970(){
var show = localStorage.setItem('show','year1970');
getData();
}
function getData(){
"use strict";
var db = TAFFY([
{
yearHistory: 1970, // id="output1970" div to display innerHTML
heading:"year1970",
partNo:"1234",
partName:"qwerty"
}
]);
var show = localStorage.getItem('show'); // year1970
db({heading:show}).each(function (name){
var partNo = name.partNo;
var partName = name.partName;
var yearHistory = name.yearHistory;
var output = "output" + yearHistory; // to match id="output1970" div to display innerHTML
output = document.getElementById(output);
output.innerHTML=''; // refresh screen between taps
output.innerHTML+="<table class='striped'><tbody><tbody>";
output.innerHTML+="<tr><td style='padding:0 10px;'>" + partNo + "</td><td>" + partName + "</td></tr>";
output.innerHTML+="</tbody></table>";
});
}
document.getElementById("year1970").addEventListener('click', show1970);
QUESTION:
What if there were two entries in the DB for 1970? The DB would look like this:
function getData(){
"use strict";
var db = TAFFY([
{
yearHistory: 1970, // id="output1970" for accordion this drawer
heading:"year1970",
partNo:"1234",
partName:"qwerty1234"
},
yearHistory: 1970, // id="output1970" for accordion this drawer
heading:"year1970",
partNo:"567",
partName:"qwerty567"
}
]);
This output has to be part of a “var i=0; i++” script so it would cycle through all the entries for 1970 and output them in their own row in:
output.innerHTML+="<tr><td style='padding:0 10px;'>" + partNo + "</td><td>" + partName + "</td></tr>";
I don’t know how to grab the DB data in the “i=0, i++” cycling format for the taffyDB. Can anyone help?