gpt4 book ai didi

jquery - 如何将多个数据添加到 jQuery 数据表单元格

转载 作者:行者123 更新时间:2023-11-28 10:13:02 24 4
gpt4 key购买 nike

我正在使用数据表来表示来自 JSON 的数据。这是我的 JSON:

[{"postIMAGE": "/images/abc.jpg", "postTITLE": "Some Text", "postURL" : "blah", "postSection" : "blah"}]

这是我的代码:

var table = $('#tableId').DataTable({
"ajax": {
"url": "loadSiteContent",
"dataSrc": "",
data: {sectionUrl: "", siteUrl: siteurl}
},
"columns": [
{"data": "postIMAGE", "render": function (data) {
alert(data);
return '<img src=' + data + ' width="154" height="115"/>';
}},
{"data": "postTITLE"},

{"data": "postURL", "render": function (data) {
return '<a href=' + data + ' target="_blank" rel="nofollow"/>' + data + '</a>';
}}
]
});

所以 View 将是这样的:

Enter image description here

但我想创建如下表格。我怎么做?单列和单笔销售中的所有详细信息。

Enter image description here

最佳答案

您可以为此使用render:
例如:

{
data: null,
name: null,
orderable: false,
render: function (data, type, row) {
return row.Field1 +
"<img src='" + row.Field2 + "' />";
}
},

换句话说,您创建单个列并使用 row.fieldName 将所有数据显示到其中,就像上面的示例一样。
我希望这是有用的。

关于jquery - 如何将多个数据添加到 jQuery 数据表单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39136831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com