如何在数据表中显示图像? [英] How to display image in datatable?
问题描述
我想在数据表中显示图像.要在数据表中显示的数据是一个数组的json数组,如下所示:
I want to show an image in my datatable.The data to be displayed in the datatable is a json array of arrays like this:
data : [["1", "John","image1.jpg"], ["2", "Jim", "image2.jpg"]]
所以在我的数据库中,我只有图像的名称,而且我不知道如何显示图像本身.
So in my database I only have the name of the image and I don't know how to display the image itself.
推荐答案
以前曾有人问过,但没有简单的数组datasrc数组.使用columnDefs
定位图像索引,使用render
构造<img>
标签:
It has been asked before, but not with a simple array of arrays datasrc. Use columnDefs
to target the index of the image, use render
to construct the <img>
tag :
var table = $('#example').DataTable({
data: data,
columnDefs: [
{ targets: 2,
render: function(data) {
return '<img src="'+data+'">'
}
}
]
})
http://jsfiddle.net/0f9Ljfjr/965/ 另请参见
http://jsfiddle.net/0f9Ljfjr/965/ See also
查看Jquery DataTable中的图片或图像
Jquery数据表在其中一列中显示图像
在数据表上显示图像
View pictures or images inside Jquery DataTable
Jquery datatables display image in one of the columns
Displaying image on Datatable
这篇关于如何在数据表中显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!