【问题标题】:How to make a custom grid view如何制作自定义网格视图
【发布时间】:2020-02-27 05:16:18
【问题描述】:

我试图按如下方式输出,但没有任何效果,我在代码中做错了什么。这是一个简单的方法,但我是一个新手。(忽略未定义的。)

<table class="table table-bordered" id="Tablev">
        <tr input type="hidden" id="trr"><th></tr>
        <tr></tr>
        <tr input type="hidden" id="date" style="display:none;" class="th-hidden-date"></tr>     
        <tr></tr>
    </table>
for (var i = 0; i <= days; i++) {
'</td>').appendTo($('#trr'));
var input = `<input type="hidden" id="date" value=${result1[i]} class="th-hidden-date" />`
$('<td>' + result1[i] + input + '</td>').appendTo($('#trr'));
}
$.each(Item1, function (index, item) {
var hiddenValues = [];
$('#Tablev').find('input:hidden').each(function () {                         
$('<tr>' +
'<td>' + item.itemname + '</td>' + '<td>' + item[$(this).val()] + '</td>').appendTo($('#Tablev'));

});
});

【问题讨论】:

    标签: javascript html gridview


    【解决方案1】:

    您需要修复代码的某些部分:

    <table class="table table-bordered" id="Tablev">
        <tr input type="hidden" id="trr"><th></tr> // This <th> need closure and shouldn't be there.
        <tr></tr>
        <tr input type="hidden" id="date" style="display:none;" class="th-hidden-date"></tr>     
        <tr></tr>
    </table>
    

    让我为你解决这个问题,至少部分...

    <table class="table table-bordered" id="Tablev">
     <thead>
      <th></th>
      <th></th> // This th will be filled with the dates..
      <th></th> // This th will be filled with the dates..
      <th></th> // This th will be filled with the dates..
     </thead>
     <tbody>
      <tr>
       <td> <input type="hidden" id="trr"> </td>
      </tr>
      <tr></tr>
      <tr>
       <td> <input type="hidden" id="date" style="display:none;" class="th-hidden-date"> </td>
      </tr>     
      <tr></tr>
     </tbody>
    </table>
    

    现在,我不明白你为什么要隐藏这些&lt;tr&gt;,现在有了JQuery,你可以这样做:

    var trow = '</tr><td>'+ result[i] + '<input type="hidden" id="date" value="'+result[i]+'" class="th-hidden-date" /></td></tr>';
    $('#trr').append(trow);
    

    注意你的代码有一些错误,在 HTML 中插入 var 时,请参阅差异并练习使用 " " 或 ' '。 在&lt;th&gt; 标签中添加一些id,以便轻松填写。

    我不是专家,我希望这可以帮助解决您的问题。

    【讨论】:

      【解决方案2】:

      我不知道你想要什么,但我想你应该有一个 2D 数组,并且每一行 id 都是数组单元格之一

      [['Allocated',0,0,undefinded],['out of order',0,0,undefined],...]
      

      然后在循环(for)中,在循环的每个步骤中,你应该填写完整的一行

      【讨论】:

      • 正如您在图像中看到的那样,我得到了以下输出,但我想将输出作为蓝色箭头传递给@AlirezaHejazi
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 2021-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多