Jquery数据表错误:TypeError:settings为null

时间:2015-04-04 16:22:18

标签: jquery jquery-datatables

大家好我正在开发一个网站并尝试使用Jquery DataTable我在FF控制台上收到此错误:TypeError:settings为null

$(settings.nTable).trigger(e +'。dt',args); 服务器代码工作正常,我以json格式返回数据,如下所示:

{"data":[ {"id": 11,
"Name": "Matthieu  Bailly",
"unitsBet": 650.46700023859739,
"UnitsWon": -4.8294003307819366  }
,{"id": 18,"Name": "Niki  Dosev",
"unitsBet": 675.54000033438206,
"UnitsWon": -22.710001260042191  }]}

这是我的HTML / JS代码

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Members Stats</title>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css" />
<link href="../CSS/PunteamCSS.css" rel="stylesheet" />
<link href="http://31.168.155.52/ASP/css/main.css" rel="stylesheet" />
<!-- JQUERY DataTable CSS-->
<link href="../DataTable/media/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="../DataTable/resources/syntax/shCore.css" rel="stylesheet" />
<link href="../DataTable/resources/demo.css" rel="stylesheet" />
<style type="text/css" class="init">
    td.details-control {
        background: url('../resources/details_open.png') no-repeat center center;
        cursor: pointer;
    }

    tr.shown td.details-control {
        background: url('../resources/details_close.png') no-repeat center center;
    }
</style>
<!-- END JQUERY DataTable CSS-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<!-- DataTable JS-->
<script src="../DataTable/js/jquery.dataTables.js"></script>
<script src="../DataTable/js/jquery.dataTables.min.js"></script>
<script src="../DataTable/resources/syntax/shCore.js"></script>
<script src="../DataTable/resources/demo.js"></script>

<script src="../PunteamScripts/AddAffiliate.js"></script>
<script src="../PunteamScripts/PunteamGlobals.js"></script>
<script src="../PunteamScripts/general.js"></script>
<script type="text/javascript" language="javascript" class="init">

    var ID = ''; //Global parameter for Loged in user

    //**************************************************************************
    //** Jquery Ready function hooks the buttons click events                  *
    //**************************************************************************
    $()
    $(document).ready(function () {
        //Load the top and bottum HTML
        $("#top").load("../HTML-Includes/top.html");
        $("#bottum").load("../HTML-Includes/bottum.html");
        // Ajax params Setup
        $.ajaxSetup({
            url: serverAddress,
            type: "POST"
        });
        // get parameters from ASP page
        var queries = {};
        $.each(document.location.search.substr(1).split('?'), function (c, q) {
            var i = q.split('=');
            ID = i[1].toString();
            AffiliateMembersStats.pType = "GetAffiliateMembersStats"
            AffiliateMembersStats.data[0].affilateId = ID
        });
        // Call to server to get Recommender detailes (Loged in user)
        $.ajax({
            type: "POST",
            processData: false,
            data: JSON.stringify({ json: AffiliateMembersStats }),
            //    dataType: "json",
            success: function (data) {

                var table = $('#membersStats').DataTable({
                    "data": data,
                    "columns": [
                        {
                            "className": 'details-control',
                            "orderable": false,
                            "data": null,
                            "defaultContent": ''
                        },
                        { "data": "Name" },
                        { "data": "unitsBet" },
                        { "data": "UnitsWon" },
                    ],
                    "order": [[1, 'asc']]
                });
            },
            failure: function (errMsg) {
                alert("Error in Get Members Stats");
            }
        });
        //End get parameter


        // Add event listener for opening and closing details
        $('#membersStats tbody').on('click', 'td.details-control', function () {
            var tr = $(this).closest('tr');
            var row = table.row(tr);

            if (row.child.isShown()) {
                // This row is already open - close it
                row.child.hide();
                tr.removeClass('shown');
            }
            else {
                // Open this row
                row.child(format(row.data())).show();
                tr.addClass('shown');
            }
        });
    });
    //*************************************************************
    //* Formatting function for row details - modify as you need **
    //*************************************************************
    function format(data) {
        // `data` is the original data object for the row
        return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">' +
            '<tr>' +
                '<td>Full name:</td>' +
                '<td>' + data.Name + '</td>' +
            '</tr>' +

            '<tr>' +
                '<td>Extra info:</td>' +
                '<td>And any further details here (images etc)...</td>' +
            '</tr>' +
        '</table>';
    }
</script>
<!--//******************* End Of Script Blosk *******************-->
</head>
<body>
<div id="top" class="col-md-12"></div>
<div class="container body-content" align="center" style="width:1200px; padding: 0 0 0 0;">
    <div id="top" class="col-md-12">
        <table id="membersStats" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th></th>
                    <th>Name</th>
                    <th>Units Bets</th>
                    <th>Units Won</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
<div id="bottum" class="col-md-12">></div>

2 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,似乎违规电话是在5070号线上进行的(我使用的是v.1.10.7):

public class DBResto_Parse extends ActionBarActivity {
    ImageView Img;
    TextView tv_name, tv_address, id;
    Gallery gallery;
    ImageSwitcher imageSwitcher;
    Integer[] imageIDs = new Integer[2];
    int msg_img;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.restoran);

        // enable up/back button
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        Button btnlihat = (Button) findViewById(R.id.lihatmap);
        btnlihat.setOnClickListener(new View.OnClickListener() {
//This is when a want to add button "view in map"

         
        Intent iIdentifikasi = getIntent();
        msg_img = iIdentifikasi.getIntExtra("dataIMG", 0);
        String msg_name = iIdentifikasi.getStringExtra("dataName");
        String msg_address = iIdentifikasi.getStringExtra("dataAddress");
        Img = (ImageView) findViewById(R.id.iv_detail);
        tv_name = (TextView) findViewById(R.id.tvName);
        tv_address = (TextView) findViewById(R.id.tvAddress);
        Img.setImageResource(msg_img);
        tv_name.setText(msg_name);
        tv_address.setText(msg_address);
    }
}

反过来由第6111行的“健全性检查”引起:

_fnCallbackFire( settings, null, 'error', [ settings, tn, msg ] );

在我的情况下,nodeName是“DIV”,因为我错误地将DataTable id分配给表格周围的DIV。

答案 1 :(得分:0)

确保您没有将id的{​​{1}}放在另一个table内。在我的情况下,我有tag而不是<div id='myDataTable'><table></table></div>