2016-06-08 104 views
0

数组的DataTable我有一个数据表结构如下所示:填充与对象等于对象

<div class="table-responsive"> 
    <table class="table table-striped table-condensed table-bordered" id="mainSutable2" style="width: 100%"> 
     <thead> 
     <tr> 
      <th>Comment Time</th> 
      <th>ID</th> 
      <th>Status</th> 
      <th>Comment</th> 
     </tr> 
     </thead> 
     <tbody> 
     </tbody> 
    </table> 
</div> 
var mainSutable2 =$('#mainSutable2').DataTable({ 
    paging: false, 
    ordering: true, 
    info:  true, 
    oLanguage:{ 
     sProcessing: 'No Data To Display', //change language of default "Processing" dialogue 
     sSearch: 'Filter' 
    }, 
    data: trackingNotes, 
    columns: [ 
     { data: "ID" }, 
     { data: "comment" }, 
     { data: "dt" }, 
     { data: "status"} 
    ] 
}); 

我想用下面来填充这个表:请注意MainSutable是另一个具有包含对象值的行的表。

var trackingNotes = {}; 
trackingNotes = mainSutable.row(this).data().tracking_notes; 

//tracikingNotes equals the following 
/* 
Object {tracking_note: Array[2]} 
tracking_note: Array[2] 
0:Object 
ID: "12345" 
comment: "yo" 
dt: "2016-06-06 12:50:46.0" 
guid: "9999" 
status: "1" 
1:Object 
ID: "12346" 
comment: "hey" 
dt: "2016-06-08 12:50:46.0" 
guid: "9999" 
status: "2" 
*/ 

如果任何人有任何信息的提示,可能会导致我在正确的方向,这将不胜感激。

回答

0

不知道为什么它不适合你。我试着复制这个问题,但它适用于我,数据显示在DataTable中,可能是脚本引用了dataTable.js,或者您没有在文档加载中调用绑定逻辑。

复制并在新页面粘贴下面的示例中并运行它,你会看到它works.Figure出比雷什么在你的代码不同,我相信它会帮你解决这个问题:

<head runat="server"> 
    <title></title> 
    <link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet" /> 
    <script src="//code.jquery.com/jquery-1.12.3.min.js"></script> 
    <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script> 
    <script> 
     $(function() { 

      var trackingNotes = []; 

      var note1 = { ID: "1", comment: "comment1", dt: new Date(), guid:"1", status: "1" }; 
      var note2 = { ID: "2", comment: "comment 2", dt: new Date(), guid: "2", status: "1" }; 
      var note3 = { ID: "3", comment: "comment 3", dt: new Date(), guid: "3", status: "0" }; 

      trackingNotes.push(note1); 
      trackingNotes.push(note2); 
      trackingNotes.push(note3); 

      var mainSutable2 = $('#mainSutable2').DataTable({ 
       paging: false, 
       ordering: true, 
       info: true, 
       oLanguage: { 
        sProcessing: 'No Data To Display', //change language of default "Processing" dialogue 
        sSearch: 'Filter' 
       }, 
       data: trackingNotes, 
       columns: [ 
        { data: "ID" }, 
        { data: "comment" }, 
        { data: "dt" }, 
        { data: "status" } 
       ] 
      }); 
     }); 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <div class="table-responsive"> 
      <table class="table table-striped table-condensed table-bordered" id="mainSutable2" style="width: 100%"> 
       <thead> 
        <tr> 
         <th>Comment Time</th> 
         <th>ID</th> 
         <th>Status</th> 
         <th>Comment</th> 
        </tr> 
       </thead> 
       <tbody> 
       </tbody> 
      </table> 
     </div> 
    </form> 
</body>