Jquery根据数据库记录添加列

jquery adding columns based on database records

本文关键字:添加 记录 数据库 Jquery      更新时间:2023-09-26

我有一个sqlite表与这些列:|日期|体重| bmi |心情|等

我想要一个表在我的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可视化插件绘制表格,该插件随着日期的进展而发布。可以想象,随着时间的推移,将有更多的条目添加到显示表的列中。以下是我到目前为止所做的(不包括绘图脚本)。我把自己搞糊涂了,现在我一团糟……任何建议都将大有帮助。我想我遇到了问题,当试图插入数据到一个表,也试图插入自己。我打赌我可能走错了路。谢谢迈克

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");
}

我想肯定会有人回答这个问题,因为这似乎是很多人都会遇到的问题。有点令人沮丧。总之,我在这里找到了一个可以适应我自己项目的答案:

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.