我想遍历数据表子行中的关联模型。
课程数据显示良好。但是参与破坏了数据表。
我使用gem'ajax-datatables-rails'。
{"data":[ {
"courses": {
"runde":"2",
"kursnavn":"SMÅBARN",
"alder":"1-5år",
"sted":"test",
"startdato":"16.06.2019",
"slutdato":"16.06.2019",
"tid":"12:12-12:23",
"delt":"0",
"tilgang":"Tidligere kurs",
"status":"Tidligere kurs",
"id":"2"
},
"participations":[{
"status_translated":"Venter på godkjenning"},{
"status_translated":"Venter på godkjenning"},{
"status_translated":"Venter på godkjenning"
}
]
}
$(document).ready(function() {
var table = $('#datatable').DataTable( {
"processing": true,
"ajax": {
"url": $('#datatable').data('source'),
"class": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
"columns": [
{"data": "courses.runde"},
{"data": "participations.status_translated"},
]
});
});
def get_raw_records
Participation.joins(:courses)
end
这是正确的吗?
function format ( d ) {
$.each($(d.participations),function(key,value){
trs+='<tr><td>'+d.participations.status_translated+'</td><tdr>'+d.participations.status_translated+'</td></tr>';
//loop through each product and append it to trs and am hoping that number of price
//values in array will be equal to number of products
});
return '<table class="table table-border table-hover">'+
'<thead>'+
'<th>Participation</th>'+
'<th>ID</th>'+
'</thead>+'
'<tbody>'+trs+'</tbody>'+
'</table>';
});
Error: "TypeError: headerCells[i] is undefined"