0

我有一个包含这些列的 sqlite 表:| 日期 | 重量 | 体重指数 | 心情 | 等等

我希望我的 html 页面上的表格在 html 页面上显示如下:

<table>
    <caption></caption>
    <thead>
         <tr>
               <td>(empty cell over row headings)</td>
               Additional tH's as needed (this is where each date entry goes)
         </tr>
    </thead>
    <tbody>
         <tr>
               <th scope="row">Weight</th>
               additional tD's as needed (this is where each weight entry goes matched with date in column heading)
         </tr>
         <tr>
               <th scope="row">BMI</th>
               additional tD's as needed (same as above)
         </tr>
    </tbody>
</table>

所以基本上我为了显示目的而翻转行和列。这就是我可以使用 jQuery Visualize 插件绘制表格的所有内容,该插件会随着日期的进行而消失。可以想象,随着时间的推移,更多条目将添加到显示表的列中。到目前为止,这是我一直在搞砸的(不包括图形脚本)。我让自己完全困惑,现在我只是一团糟......任何建议都会有很大帮助。我想我在尝试将数据插入到也试图插入自身的表中时遇到了问题。我敢打赌,我可能会犯这个错误。谢谢迈克

function homeSuccess(tx, results) {
    // Gets initial count of records in table...
    var entries = results.rows.length;
    // Iterates over all the existing records...
    for (var i = 0; i < entries; ++i) {
        // The following element id's can be found in the div's within the table below, see element.innerHTML line...
        var element = document.getElementById('colDate');
        element.innerHTML += '<th scope="col">' + results.rows.item(i).timeStamp + '</th>';
        var element2 = document.getElementById('tdWeight');
        element2.innerHTML += '<td>' + results.rows.item(i).weight + '</td>';
        var element3 = document.getElementById('tdBmi');
        element3.innerHTML += '<td>' + results.rows.item(i).bmi + '</td>';
    };
    // 'screenView2 is a placeholder on the main html page...
    var element = document.getElementById('screenView2');
    element.innerHTML = '<br /><br /><h1>Data:</h1><br />Number of entries: ' + entries + '<br />' + '<table><caption>Mikes Health</caption><thead><tr><td></td><div id="colDate"></div></tr></thead><tbody><tr><th scope="row">Weight</th><div id="colWeight"></div></tr><tr><th scope="row">BMI</th><div id="colBmi"></div></tr></tbody></table>';

    // This section is just a test trying to plug in static elements prior to trying database data... When using this section I had the iteration section commented out.
    var element2 = document.getElementById('colDate');
    element2.innerHTML = '<th scope="col">4-1-13</th>';

    var element3 = document.getElementById('colWeight');
    element3.innerHTML = '<td scope="col">123</td>';

    var element4 = document.getElementById('colBmi');
    element4.innerHTML = '<td scope="col">321</td>';
}

function homeQuery(tx) {
    console.log("entering homeQuery");
    tx.executeSql('SELECT * FROM HEALTHGRAPH', [], homeSuccess, onSqlError);
    console.log("leaving homeQuery");
}

// Function that is called on initial page load 
function homeDBopen() {
    console.log("opening db for home data");
    theDB = window.openDatabase("hgDB", "1.0", "HealthGraph", 3 * 1024 * 1024);
    theDB.transaction(homeQuery, onTxError, onTxSuccess);
    console.log("leaving homeDBopen");
}
4

1 回答 1

0

肯定有人会回答这个问题,因为这似乎是很多人必须遇到的问题。有点气馁。无论如何,我在这里找到了一个可以适应我自己的项目的答案:

http://msdn.microsoft.com/en-us/library/ie/ms532998(v=vs.85).aspx

// Insert cells into the header row.
  for (i=0; i<heading.length; i++)
  {
    oCell = oRow.insertCell(-1);... etc.
于 2013-04-16T14:23:11.537 回答