2016-06-08 100 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>