数据表:未捕获的类型错误:无法读取的未定义的属性'长'? [英] DataTables: Uncaught TypeError: Cannot read property 'length' of undefined?

查看:2470
本文介绍了数据表:未捕获的类型错误:无法读取的未定义的属性'长'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,这里是我的AJAX调用的数据表的表对象。我试图让JSON填写,只有行的表,因为它已经有标题行。

So, here is my AJAX call for the DataTables table object. I am trying to get the JSON to fill in a table with rows only, as it already has header rows.

我不明白,什么该数据表Ajax调用,因为他们从一个版本不同,其他的语法。

I am not clear as to what the syntax of the DataTables ajax calls are, as they differ from one version to the other.

$('#MainContentPlaceHolder_business_return_flights').dataTable({
    "ajax": {
        "url": "Browse.aspx/GetBusinessFlights",
        "type": "POST",
        "contentType": "application/json; charset=utf-8",
        "dataType": "json"
    }
});

我不断收到错误:未捕获的类型错误:无法读取的未定义的属性长度

下面是JSON返回:

{
  "d":{
  "draw":"1",
  "recordsTotal":"70",
  "recordsFiltered":"70",
  "aData":[
             [
                "BI 098",
                "London (LHR)",
                "Dubai",
                "08-08-2014",
                "12:55 PM",
                "11:55 PM",
                "Royal Brunei",
                "1",
                "0",
                "1300",
                "\u003cbutton type=\"button\" href=\"javascript:void(0)\" onclick=\"selectFlight($(this))\" data-toggle=\"oflight\" class=\"btn btn-block btn-info\"\u003eBook\u003c/button\u003e"
             ],
             [
                "CY 383",
                "Dubai",
                "Larnaca",
                "08-06-2014",
                "1:45 PM",
                "4:05 PM",
                "Cyprus Airways",
                "1",
                "0",
                "1100",
                "\u003cbutton type=\"button\" href=\"javascript:void(0)\" onclick=\"selectFlight($(this))\" data-toggle=\"oflight\" class=\"btn btn-block btn-info\"\u003eBook\u003c/button\u003e"
             ]
        ]
    }
}

更新:这是我回报的方法:

Update: Here is my return method:

[WebMethod]
public static Dictionary<string, object> GetBusinessFlights()
{
    listRows = new List<List<string>>();
    business = new Table();
    economy = new Table();

    FillTable(economy, business, scheduledFlights.List);

    foreach (TableRow row in business.Rows)
    {
        listRow = new List<string>();

        foreach (TableCell cell in row.Cells)
        {
            listRow.Add(cell.Text);
        }

        listRows.Add(listRow);
    }

    field = new Dictionary<string, object>() { { "draw", "1" }, { "recordsTotal", economy.Rows.Count.ToString() }, { "recordsFiltered", economy.Rows.Count.ToString() }, { "aData", listRows } };

    return field;

}

注意: FillTable()只填写数据到商业和经济的表对象

Note: The FillTable() only fills in the data into the business and economy Table objects.

推荐答案

嗯,我想给你数据表的旅程,这可能大干一场。

Well i guess this could make inroads to you datatables journey .

数据表中填充数据:

$('#myDataTable').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": 'DataProvider', // This will be controller action method with Json return type which in turn fills your DataTable 
            "bJQueryUI": true,
            "aoColumns": [
                         { "sName": "ID"  },
                         { "sName": "COMPANY_NAME" },
                         { "sName": "ADDRESS" },
                         { "sName": "TOWN" }
            ]

        });

随着Ajax调用意味着你必须设置是这样的:

$.ajax({
                        "type": "GET",
                        "dataType": 'json',
                        "contentType": "application/json; charset=utf-8",
                        "url": //source url,
                        "data": {},
                        "success": function (data) {
                            //on success you will reach into it
                        }
                    });

您若设置这样意味着它很酷控制器返回类型:

DataProvider的操作方法在

inside DataProvider action method

return Json(new
            {
                sEcho = param.sEcho, //communication b/w subsequent calls
                iTotalRecords = //your count here,
                iTotalDisplayRecords = //per page display records count,
                aaData = your array list which will bind to dataTable
            },
                        JsonRequestBehavior.AllowGet);

PS::当我是新来的数据表,我开始与这些真棒文章前进。这会给你更好地理解和放大器;示例项目包括:

PS : When i am new to datatables i began with these awesome articles to move forward . This will give you better idea & sample projects included :

http://www.$c$cproject.com/Articles/155422/jQuery-DataTables-and-ASP-NET-MVC-Integration-Part

问候

这篇关于数据表:未捕获的类型错误:无法读取的未定义的属性'长'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆