0
<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在我的骨幹Initialize
功能我設置爲我的集合的引用,其調用API從數據庫中獲取數據。在這個特定的實例中,它獲取了staff表中的所有行。
this.staff = options.staff;
在我的骨幹render
功能我有用於填充數據表的表下面的代碼:
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
}]
});
在一個新的功能,我希望能夠得到每個項目的Index
在listTemplateTbody
。任何幫助將非常感激。
createCourseTpl: function(e) {
//get id of each item here?
}
雖然此代碼段可能會解決問題,但[包括解釋](// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers)確實有助於提高帖子的質量。請記住,您將來會爲讀者回答問題,而這些人可能不知道您的代碼建議的原因。也請儘量不要使用解釋性註釋來擠佔代碼,因爲這會降低代碼和解釋的可讀性! – FrankerZ
添加了解釋。 – SiddP