jquery表解析不工作

jquery表解析不工作,jquery,Jquery,我很难理解为什么创建表的jquery(如下所示)不起作用。所有数据值在数值上都是正确的。问题在于,在我看来: 正确创建的表格标题 然后是一行(水平),其中所有行彼此相邻打印,如中所示: col1 col2 col3 col4 col5 1 2 4 5 5 6 7 8 9 10 11 12 13 14 15 应该是什么时候 col1 col2 col3 col4 col5 1 2 4 5 5 6 7

我很难理解为什么创建表的jquery(如下所示)不起作用。所有数据值在数值上都是正确的。问题在于,在我看来:

正确创建的表格标题 然后是一行(水平),其中所有行彼此相邻打印,如中所示:

col1 col2 col3 col4 col5 
1    2    4    5    5    6   7   8   9   10  11  12   13 14  15
应该是什么时候

col1 col2 col3 col4 col5 
1    2    4    5    5    
6    7    8    9   10
11  12   13   14   15
任何关于我做错了什么的暗示都将不胜感激。我已经看了好几个小时的代码了。我知道我错过了什么

            if (jsonData.length > 0) {
            $('#grid2R').empty();
            $('#grid2R').append("RESETS <br />");
            $('#grid2R').append('<table id="grid-resets" class="table table-condensed table-hover table-striped">');
            $('#grid2R').append('<thead>'
                + '<tr>'
                + '<th data-column-id="col1" data-order="desc">col1</th>'
                + '<th data-column-id="col2">col2</th>'
                + '<th data-column-id="col3" >col3</th>'
                + '<th data-column-id="col4">col4</th>'
                + '<th data-column-id="col5">col5</th>'
                + '</tr>'
                + '</thead>');

            for (i = 0; i < resets.length; i++) {
                var col1Value= jsonData[i].col1Value;
                var col2Value= jsonData[i].col2Value;
                var col3Value= jsonData[i].col3Value;
                var col4Value= jsonData[i].col4Value;
                var col5Value= jsonData[i].col5Value;
                if (i == 0) {
                    $('#grid2R').append('<tbody>');
                }
                $('#grid2R').append(
                    + '<tr>'
                    + '<td class="aTD">' + col1Value+ '</td>'
                    + '<td class="aTD">' + col2Value+ '</td>'
                    + '<td class="aTD">' + col3Value+ '</td>'
                    + '<td class="aTD">' + col4Value+ '</td>'
                    + '<td class="aTD">' + col5Value+ '</td>'
                    + '</tr>');
                if (i == resets.length - 1) {
                    $('#grid2R').append('</tbody></table>');
                }
            }
        }
        else {
            $('#grid2R').empty();
            $('#grid2R').append("No Resets we found");
        }
    });
    $("#imgSpinner1").hide();
if(jsonData.length>0){
$('#grid2R').empty();
$('#grid2R')。追加(“重置
”); $('#grid2R')。追加(''); $('#grid2R')。附加('' + '' +“col1” +“col2” +“col3” +“可乐4” +“col5” + '' + ''); 对于(i=0;i
jQuery用于附加一个或多个元素,而不是HTML代码

尝试类似以下内容:

// create and append the tbody element
var tbody = $('<tbody>').appendTo( '#grid2R' );

for (i = 0; i < resets.length; i++) {
    var col1Value= jsonData[i].col1Value;
    var col2Value= jsonData[i].col2Value;
    var col3Value= jsonData[i].col3Value;
    var col4Value= jsonData[i].col4Value;
    var col5Value= jsonData[i].col5Value;

    // append rows to the tbody element
    tbody.append(
        '<tr>'
        + '<td class="aTD">' + col1Value+ '</td>'
        + '<td class="aTD">' + col2Value+ '</td>'
        + '<td class="aTD">' + col3Value+ '</td>'
        + '<td class="aTD">' + col4Value+ '</td>'
        + '<td class="aTD">' + col5Value+ '</td>'
        + '</tr>');
}
初始的
+“”
尝试将
“”
计算为一个数字,结果是
NaN
,因此无法获得所需的行

此外,您只需添加
tbody
一次,然后将其追加。不要尝试附加结束语

var tb = $("<tbody>").appendTo( $('#grid2R') );

for (i = 0; i < resets.length; i++) {
  var col1Value= jsonData[i].col1Value;
  var col2Value= jsonData[i].col2Value;
  var col3Value= jsonData[i].col3Value;
  var col4Value= jsonData[i].col4Value;
  var col5Value= jsonData[i].col5Value;

  tb.append(
      '<tr>'
      + '<td class="aTD">' + col1Value+ '</td>'
      + '<td class="aTD">' + col2Value+ '</td>'
      + '<td class="aTD">' + col3Value+ '</td>'
      + '<td class="aTD">' + col4Value+ '</td>'
      + '<td class="aTD">' + col5Value+ '</td>'
      + '</tr>');
}
var tb=$(“”)。附录($('#grid2R');
对于(i=0;i
如果只有5列,则循环中需要一个计数器(或第二个循环)

达到5后,需要结束当前表行并开始新的表行

jQuery
.append()
不仅仅是一个字符串连接:
$('#grid2R').append('')无效。您可以在
#grid2R
中附加一个tbody,并使用
.HTML()
appendTo
append()
将HTML插入其中。
var tbody=$(“#grid2R”).append(“”)
tbody
设置为
#grid2R
元素,而不是附加元素。对
+'
var tb = $("<tbody>").appendTo( $('#grid2R') );

for (i = 0; i < resets.length; i++) {
  var col1Value= jsonData[i].col1Value;
  var col2Value= jsonData[i].col2Value;
  var col3Value= jsonData[i].col3Value;
  var col4Value= jsonData[i].col4Value;
  var col5Value= jsonData[i].col5Value;

  tb.append(
      '<tr>'
      + '<td class="aTD">' + col1Value+ '</td>'
      + '<td class="aTD">' + col2Value+ '</td>'
      + '<td class="aTD">' + col3Value+ '</td>'
      + '<td class="aTD">' + col4Value+ '</td>'
      + '<td class="aTD">' + col5Value+ '</td>'
      + '</tr>');
}