Upon receiving a response from an AJAX call, my task is to create a bootstrap-table with the data. The response contains an array with information about images, such as their paths and names. However, when trying to populate the bootstrap-table with this data, only a single image is displayed instead of all the images in the array.
Here is my function and AJAX call:
function printCatchTable(){
var $table = $('#TableLastCaught');
$.ajax({
type: "GET",
url: '/api/lastcaught',
success: function(response) {
for(var i =0;i < response.length ;i++){
var item = response[i];
var picinfos = item.picinfos;
for(var x in picinfos){
var filename = picinfos[x].filename;
}
faengeTableData.push({
_id: item._id,
date: item.datum,
time: item.uhrzeit,
pics: filename,
}
$table.bootstrapTable({data: faengeTableData});
$table.bootstrapTable('togglePagination');
}
})
}
function imageFormatter(value, row) {
return '<img src="files/'+value+'" />';
}
This is the data received:
{
"_id":"5c81253a4a582827f09969a7",
"date":"2019-03-07",
"time":"10:11",
"picinfos":[
{
"filepath":"/files/1551967546627.jpg",
"mimetype":"image/jpeg",
"filename":"1551967546627.jpg",
"size":322289,
"metadata":{
"GPSLat":"",
"GPSLon":"",
"CreateDate":"",
"CreateTime":""
}
},
{
"filepath":"/files/1551967546634.jpg",
"mimetype":"image/jpeg",
"filename":"1551967546634.jpg",
"size":275692,
"metadata":{
"GPSLat":"",
"GPSLon":"",
"CreateDate":"",
"CreateTime":""
}
},
{
"filepath":"/files/1551967546638.jpg",
"mimetype":"image/jpeg",
"filename":"1551967546638.jpg",
"size":261305,
"metadata":{
"GPSLat":"",
"GPSLon":"",
"CreateDate":"",
"CreateTime":""
}
}
],
"userid":"5c09116a4e2d1f1cc9d48d6a",
"__v":0
}
Currently, only one picture is displayed under the "Pics" column:
<th data-field="bilder" data-sortable="false" data-formatter="imageFormatter">Pics</th>
<tr id="5c8a196cc7b15419d5755153" data-index="1">
<td style="">2019-03-14</td>
<td style="">6:15:19</td>
<td style=""><img src="files/1552554348794.jpg"></td>
</tr>
If I don't use the formatter, I see:
<tr id="5c8a196cc7b15419d5755153" data-index="1">
<td style="">2019-03-14</td><td style="">6:15:19</td>
<td style="">1552554348794.jpg</td>
</tr>
The question remains: how can I display all the images in the table column/row and have the imageFormatter construct the image source string?