带有json(ajax)的新行中的Datatables对象

克雷波·沃尔夫(Crapo Wolf)

到目前为止,我已经能够使用datatables毫无问题地显示来自json的ajax数据。但是今天我遇到了这个问题。Json具有以下结构:

{
    "aaData": [
        {
            "id": 22,
            "name": "flavor 22",
            "flavorItem": [
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                },
                {
                    "hostSuffix": "google"
                },
                {
                    "hostSuffix": "yahoo"
                }
            ]
        }
    ]
}

当加载到数据表中时,这将向我显示同一行中的所有对象“ hostSuffix”。如何显示每个对象的换行符?

我的剧本:

$("#example").dataTable({
    "serverSide": true,
    "searching": false,
    "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
    "iDisplayLength": 10,
    "ajax": "<c:url value='/ajax/selectflavorEditor?id=22'/>",
    "columns": [
        {"data": "flavorItem[, ].hostSuffix"}

    ]
});
戴维·康拉德

您必须设置dataSrc指向嵌套数组flavorItem

$("#example").dataTable({
    "serverSide": true,
    "searching": false,
    "aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "All"]],
    "iDisplayLength": 10,
    "ajax": {
        url: "<c:url value='/ajax/selectflavorEditor?id=22'/>",
        dataSrc: function(json) {
            return json['aaData'][0].flavorItem
        }
    },
    "columns": [
        {"data": "hostSuffix"}
    ]
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用带有 AJAX 和 JSON 文件的 DataTables 的表中没有可用数据

如何将带有多个对象的JSON数据中的值插入MySQL中的行?

返回带有过滤结果的新JSON对象

Ajax安全性:外部带有对象的JSON

将带有ajax的json对象传递给php

在C#中创建带有或不带有新对象的对象

MOQ从带有参数的方法中返回新对象

如何在带有窗口的对象中创建新值

带有ajax的DataTables 1.10.6,请求第0行的未知参数0

使用带有PHP和AJAX的JQuery DataTables的无效JSON响应错误

ODT 文档中带有 jOpenDocument 的字段中的新行

带有JSON数据的jQuery DataTables列表

摔倒JavaScript对象(带有新对象)?

50k 行到带有 json 数据(文本、标题、排序)的 DataTables

如何在带有变量的JLabel中添加新行

从文件中读取并返回带有循环的新行

结果中带有新行的apache ant loadfile

如何遍历 json 对象并使用 Javascript 形成一个带有连接值的新对象?

一行中带有方法的对象

带有json的java中的对象返回数组

带有对象问题的 Arraylist 中的 Firebase JSON 到 Arraylist

从带有方括号的json对象中检索数据

带有子对象的json中的Angulajs ng-options

带有JSON对象的Angular js中的图表

dc.js中带有JSON对象的线图

PHP返回带有JSON数组中特殊字符的对象

解析属性键中带有特殊字符的JSON对象

TableView 中带有 JSON 对象的搜索栏 - Swift

在php中创建JSON对象(带有数组)