Note that there are some explanatory texts on larger screens.

plurals
  1. POText not displaying in right order
    primarykey
    data
    text
    <p>I'm trying to get JSON data to display in a paragraph, but have a divider between data taken on different dates.</p> <pre><code>function getAllLogs(emId) { $.getJSON('datafile.json', function(data) { $("#" + emId).html("All logs:&lt;br&gt;"); var firstDateDisplayed = false; $.each(data, function(index, value) { //Only displays dates once, then all log sheets for that date if (firstDateDisplayed === false || data[index-1].log_sheet.time !== value.log_sheet.time) { $("#" + emId).append("&lt;br&gt;----------------&lt;br&gt;"); //Formats and appends date to a paragraph getLogDate(emId, index); firstDateDisplayed = true; } //Formats and appends time to a paragraph getLogTime(emId, index); //Formats and appends all data to a paragraph getLogData(emId, index); }); }); } </code></pre> <p>What I want:</p> <pre><code>All logs: ---------------- Date 1 Time 1 Data 1 Time 2 Data 2 Time 3 Data 3 ---------------- Date 2 Time 4 Data 4 Time 5 Data 5 </code></pre> <p>What I get:</p> <pre><code>---------------- ---------------- Date 1 Time 1 Data 1 Time 2 Data 2 Time 3 Data 3 Date 2 Time 4 Data 4 Time 5 Data 5 </code></pre> <p>Example JSON data:</p> <pre><code>[ { "log_sheet": { "data":"4", "date":"2012-07-27T00:00:00-06:00", "time":"2000-01-01T02:15:00Z", "more_data":"7" } }, { "log_sheet": { "data":"8, "date":"2012-07-27T00:00:00-06:00", "time":"2000-01-01T07:30:00Z", "more_data":"3" } } ] </code></pre> <p>How do I fix this? My dates display correctly, but why don't the dividers?</p> <p>getLogTime function:</p> <pre><code>//Gets, formats and displays the time for the current log sheet in the //header of a collapsible menu or paragraph function getLogTime(emId, logNum) { //Accesses the JSON file $.getJSON('datafile.json', function(data) { //Takes only the part of the string that corresponds to time var time = data[logNum].log_sheet.measured_at_time.substring(11,16); //Formats time to 12 hour clock according to the hour switch (time.substring(0, 2)) { case "00": //Changes 00 to 12 and adds am time = time.replace(/00/, "12") + " am"; break; case "01": case "02": case "03": case "04": case "05": case "06": case "07": case "08": case "09": //Removes extra 0 and adds am time = time.replace(/0/, "") + " am"; break; case "10": case "11": //Adds am time += " am"; break; case "12": //Adds pm time += " pm"; break; case "13": //Replaces 13 with 1 and adds pm time = time.replace(/13/, "1") + " pm" case "14": //Replaces 14 with 2 and adds pm time = time.replace(/14/, "2") + " pm"; break; case "15": //Replaces 15 with 3 and adds pm time = time.replace(/15/, "3") + " pm"; break; case "16": //Replaces 16 with 4 and adds pm time = time.replace(/16/, "4") + " pm"; break; case "17": //Replaces 17 with 5 and adds pm time = time.replace(/17/, "5") + " pm"; break; case "18": //Replaces 18 with 6 and adds pm time = time.replace(/18/, "6") + " pm"; break; case "19": //Replaces 19 with 7 and adds pm time = time.replace(/19/, "7") + " pm"; break; case "20": //Replaces 20 with 8 and adds pm time = time.replace(/20/, "8") + " pm"; break; case "21": //Replaces 21 with 9 and adds pm time = time.replace(/21/, "9") + " pm"; break; case "22": //Replaces 22 with 10 and adds pm time = time.replace(/22/, "10") + " pm"; break; case "23": //Replaces 23 with 11 and adds pm time = time.replace(/23/, "11") + " pm"; break; } //Uses only a portion of the string to accommodate possible future //numbers if (emId.substring(0,4) === "time") { //Sets text in header to time $("#" + emId + " .ui-btn-text").html(time); } else { //For displaying all of the logs $("#" + emId).append(time + "&lt;br&gt;"); } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload