2016-08-05 5 views
0

内のすべてのアイテムのIDを取得し、私は私のバックボーンInitialize機能では、テーブルのDataTableのテーブル

<div role="tabpanel" class="tab-pane fade col-sm-12" id="trainerList" style="max-width: 1000px;"> 
    <table id="trainerListTable" class="table table-condensed table-striped" style="width: 100%;"> 
     <thead> 
      <tr> 
       <th></th> 
       <th></th> 
       <th>Staff ID</th> 
       <th>Trainer</th> 
       <th>Team</th> 
       <th>Department</th> 
      </tr> 
     </thead> 
     <tbody id="listTemplateTbody"></tbody> 
    </table> 
</div> 

次のHTMLを持っている私は、データベースからデータを取得するためのAPIを呼び出して、私のコレクションへの参照を設定します。この特定のインスタンスでは、staffテーブルのすべての行が取得されています。私は、DataTableのテーブルを埋めるために、次のコード持っている私のバックボーンrender機能で

this.staff = options.staff; 

:新しい機能で

this.ui.listTemplateTbody.empty(); 

this.staff.each(function(template) { 
    var profileImg = template.get('PictureUri') || "/images/placeholderUser.png"; 
    self.ui.listTemplateTbody.append(self.listTabletpl({ 
     Index: template.get('Index'), 
     StaffId: template.get('Id'), 
     Forename: template.get('forename'), 
     Surname: template.get('surname'), 
     Team: template.get('Team') || "No Team", 
     Department: template.get('DepartmentId') || "No Department", 
     Image: '<img class="createImageTableIcon" src="' + profileImg + '" />' 
    })); 
}); 

this.staffTable = $('#trainerListTable').DataTable({ 
    "aLengthMenu": [ 
     [5, 10, 25, 50, -1], 
     [5, 10, 25, 50, "all"] 
    ], 
    "iDisplayLength": 10, 
    "order": [ 
     [2, "DESC"] 
    ], 
    "columnDefs": [{ 
     "orderable": false, 
     "targets": [0, 1] 
    }, { 
     "width": "5%", 
     "targets": 0 
    }, { 
     "width": "5%", 
     "targets": 1 
    }, { 
     "width": "10%", 
     "targets": 2 
    }, { 
     "width": "40%", 
     "targets": 3 
    }, { 
     "width": "20%", 
     "targets": 4 
    }, { 
     "width": "20%", 
     "targets": 5 
    }] 
}); 

を私はlistTemplateTbodyの各項目のIndexを取得できるようにしたいです。どんな助けでも大歓迎です。

createCourseTpl: function(e) { 
    //get id of each item here? 
} 

答えて

2
$('#trainerListTable').each(function(index, domobj) { 
    //your logic 
}); 

説明:

あなたのIDのtrainerListTableを選択し、記載されたインデックスがあなたの反復回数を与え、また、親とdomobjからの要素のインデックスが子そのものであるとして子供を反復たとえばインデックス0の場合、theadはdom要素になります。そうすれば、操作する要素と操作しない要素をロジックに書くことができます。

+0

このコードスニペットは問題を解決するかもしれませんが、[説明を含む](// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)本当にあなたの投稿の質を向上させるのに役立ちます。将来読者の質問に答えていることを覚えておいてください。そうした人々はあなたのコード提案の理由を知らないかもしれません。また、コードと説明の両方の可読性が低下するため、説明的なコメントを使用してコードを混乱させないようにしてください。 – FrankerZ

+0

説明が追加されました。 – SiddP

関連する問題