0

我有这样的代码

 $.ajax({ 
                type : 'POST',
                url : 'classfication_of_productjson.html',
                dataType : 'json',
                data : {
                    "search_bunrui_code" : code,
                    "orderType" : orderType,
                    "search_base_date_from" : search_base_date_from,
                    "search_base_date_to" : search_base_date_to,
                    "compare_date_from" : compare_date_from,
                    "compare_date_to" : compare_date_to,
                    "compare_menu" : compare_menu,
                    "shopCode0000" : shopCode0000,
                    "shopCode0001" : shopCode0001,
                    "shopCode0002" : shopCode0002,
                    "shopCode0009" : shopCode0009,
                    "shopCode0003" : shopCode0003,
                    "shopCode0006" : shopCode0006,
                    "shopCode9000" : shopCode9000,
                    "shopCode9001" : shopCode9001
                },


                success : function(data) {
                        $('#dataTable').dataTable({
                        "bProcessing": true,
                        "bServerSide": true,
                        "aaSorting": [[1,'desc']],
                        "aaData": $.parseJSON(data),
                        "iDisplayLength": 10,
                        "bDeferRender": true,
                        "bJQueryUI": true,
                        "sPaginationType": "two_button",
                        "bRetrieve":[],
                        "bDestroy": [],
                        "aoColumns": [
                            {"mData": "brand_code"},
                            {"mData": "brand_name"},
                            {"mData": "bunrui_code"},
                            {"mData": "compare_jyutyuu_hanbai"},
                            {"mData": "compare_jyutyuu_profit"},
                            {"mData": "compare_jyutyuu_profit_rate"},
                            {"mData": "compare_jyutyuu_sikiri"},
                            {"mData": "compare_jyutyuu_teika"},
                            {"mData": "compare_nouhin_hanbai"},
                            {"mData": "compare_nouhin_profit"},
                            {"mData": "compare_nouhin_profit_rate"},
                            {"mData": "compare_nouhin_sikiri"},
                            {"mData": "compare_nouhin_teika"},
                            {"mData": "compare_syouhin_count"},
                            {"mData": "dummy_column"},
                            {"mData": "jyutyuu_hanbai"},
                            {"mData": "jyutyuu_profit"},
                            {"mData": "jyutyuu_profit_rate"},
                            {"mData": "jyutyuu_sikiri"},
                            {"mData": "jyutyuu_teika"},
                            {"mData": "list_no"},
                            {"mData": "nouhin_hanbai"},
                            {"mData": "nouhin_profit"},
                            {"mData": "nouhin_profit_rate"},
                            {"mData": "nouhin_sikiri"},
                            {"mData": "nouhin_teika"},
                            {"mData": "rate_jyutyuu_hanbai"},
                            {"mData": "rate_jyutyuu_profit"},
                            {"mData": "rate_jyutyuu_profit_rate"},
                            {"mData": "rate_jyutyuu_sikiri"},
                            {"mData": "rate_jyutyuu_teika"},
                            {"mData": "rate_nouhin_hanbai"},
                            {"mData": "rate_nouhin_profit"},
                            {"mData": "rate_nouhin_profit_rate"},
                            {"mData": "rate_nouhin_sikiri"},
                            {"mData": "rate_nouhin_teika"},
                            {"mData": "rate_syouhin_count"},
                            {"mData": "siire_code"},
                            {"mData": "siire_name"},
                            {"mData": "siire_rate"},
                            {"mData": "syouhin_code"}
                        ]

                    });

我有这样的服务器返回的 json 数据

{
    "aaData": [
        {
            "brand_code": "1586",
            "brand_name": "74Daijiro:74ダイジロー",
            "bunrui_code": "0001",
            "bunrui_name": "バイク本体",
            "compare_jyutyuu_hanbai": 0,
            "compare_jyutyuu_profit": 0,
            "compare_jyutyuu_profit_rate": 0,
            "compare_jyutyuu_sikiri": 0,
            "compare_jyutyuu_teika": 0,
            "compare_nouhin_hanbai": 0,
            "compare_nouhin_profit": 0,
            "compare_nouhin_profit_rate": 0,
            "compare_nouhin_sikiri": 0,
            "compare_nouhin_teika": 0,
            "compare_syouhin_count": 0,
            "dummy_column": "",
            "jyutyuu_hanbai": 227000,
            "jyutyuu_profit": 73091,
            "jyutyuu_profit_rate": 32.19,
            "jyutyuu_sikiri": 153909,
            "jyutyuu_teika": 227000,
            "list_no": 0,
            "nouhin_hanbai": 0,
            "nouhin_profit": 0,
            "nouhin_profit_rate": 0,
            "nouhin_sikiri": 0,
            "nouhin_teika": 0,
            "rate_jyutyuu_hanbai": 0,
            "rate_jyutyuu_profit": 0,
            "rate_jyutyuu_profit_rate": 0,
            "rate_jyutyuu_sikiri": 0,
            "rate_jyutyuu_teika": 0,
            "rate_nouhin_hanbai": 0,
            "rate_nouhin_profit": 0,
            "rate_nouhin_profit_rate": 0,
            "rate_nouhin_sikiri": 0,
            "rate_nouhin_teika": 0,
            "rate_syouhin_count": 0,
            "siire_code": null,
            "siire_name": null,
            "siire_rate": 85,
            "syouhin_code": "74d001",
            "syouhin_count": 1,
            "syouhin_spec": "",
            "syouhin_sys_code": "20521938",
            "syouhin_sys_name": "74Daijiro 車体"
        },
        {
            "brand_code": "1360",
            "brand_name": "TERRA MOTORS:テラモーターズ",
            "bunrui_code": "0001",
            "bunrui_name": "バイク本体",
            "compare_jyutyuu_hanbai": 0,
            "compare_jyutyuu_profit": 0,
            "compare_jyutyuu_profit_rate": 0,
            "compare_jyutyuu_sikiri": 0,
            "compare_jyutyuu_teika": 0,
            "compare_nouhin_hanbai": 0,
            "compare_nouhin_profit": 0,
            "compare_nouhin_profit_rate": 0,
            "compare_nouhin_sikiri": 0,
            "compare_nouhin_teika": 0,
            "compare_syouhin_count": 0,
            "dummy_column": "",
            "jyutyuu_hanbai": 38000,
            "jyutyuu_profit": 12137,
            "jyutyuu_profit_rate": 31.93,
            "jyutyuu_sikiri": 25863,
            "jyutyuu_teika": 38000,
            "list_no": 0,
            "nouhin_hanbai": 38000,
            "nouhin_profit": 12137,
            "nouhin_profit_rate": 31.93,
            "nouhin_sikiri": 25863,
            "nouhin_teika": 38000,
            "rate_jyutyuu_hanbai": 0,
            "rate_jyutyuu_profit": 0,
            "rate_jyutyuu_profit_rate": 0,
            "rate_jyutyuu_sikiri": 0,
            "rate_jyutyuu_teika": 0,
            "rate_nouhin_hanbai": 0,
            "rate_nouhin_profit": 0,
            "rate_nouhin_profit_rate": 0,
            "rate_nouhin_sikiri": 0,
            "rate_nouhin_teika": 0,
            "rate_syouhin_count": 0,
            "siire_code": null,
            "siire_name": null,
            "siire_rate": 76,
            "syouhin_code": "w-charge-004",
            "syouhin_count": 1,
            "syouhin_spec": "",
            "syouhin_sys_code": "19872078",
            "syouhin_sys_name": "アクシア 専用充電器"
        }
    ],
    "iTotalDisplayRecords": 2,
    "iTotalRecords": 2,
    "sEcho": 1
}

但是数据表总是显示为空。任何有数据表经验的人请给一个建议!谢谢你的帮助

4

1 回答 1

0

如果没有提供更多错误信息(例如控制台错误)或实时示例,我们无能为力。但是快速猜测一下,您的aaData密钥使用了解析的 JSON,其中还包含一些非数据绒毛(即sEcho)。假设该参数只想接收aaData您的来源。

所以尝试改变:

"aaData": $.parseJSON(data),

"aaData": $.parseJSON(data).aaData,

注意:最好的做法是在数据表初始化程序之外解析 JSON,并在尝试使用之前检查 aaData 键是否存在。但是上面的代码应该可以告诉您错误是否是我认为的错误

于 2013-06-11T09:26:02.180 回答