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

标签 jquery css ajax datatables

我正在使用数据表来表示来自 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/

相关文章:

javascript - 如何从json中获取数据并将其保存到数据库中?

javascript - js中添加两个变量

html - 子菜单在 IE 和 Chrome 中不起作用。在 FF、Opera 中工作

jquery - .ajax 帖子上出现 401 未经授权

php - 如何使用 PHP 跟踪数据库表中的更新?

javascript - 切换 css 和 html

jquery - FB :login-button image change

javascript - 在更改事件上为现有 javascript 代码添加值

jquery - 交换 jQuery 中的两个元素

css - 与外部样式表的样式链接