我正在使用JQuery DataTables我得到TypeError: aData is undefined
以下是我的JS代码:
$('#brands').DataTable({
dom: "Bfrtip",
serverside: true,
ajax: "getCompanies",
columns: [
{data: "name"},
{data: "last_name"},
{data: "gender"},
{data: "city"},
],
select: true,
});
这是我的JSON响应
{
"data": [{
"DT_RowId": "row_1",
"id": 1,
"company_id": 1,
"name": "Saeed",
"last_name": "last_name",
"email": "uandsaeed
@gmail.com",
"password": "$2y$10$P4d496V0FPNF7DtcOZBFVeNBe5DYpCvR9nSBtoZs9.iI0DgzisuIW",
"phone_no": "02123456744",
"address": "fsd road abk",
"skype_id": "",
"city": "Lahore",
"gender": "",
"shoe_size": null,
"user_type": "CompanyAdmin",
"user_image": null,
"remember_token": "j2eu3QeYfql1pdbgcrypYnErAHYBdlyxmOCzMF3rT1XQtpV48oYNwEtVHwrk",
"created_at": "2016-07-15 20:02:55",
"updated_at": "2016-07-29 10:30:27",
"deleted_at": null
}, {
"DT_RowId": "row_3",
"id": 3,
"company_id": 2,
"name": "Saeed nm",
"last_name": "",
"email": "saeed@gmail.com",
"password": "$2y$10$u2qDYiBW2mPGH6IL0VsPzO
\/YlUFI3QiizUgBPWPAI842r58ytsa..",
"phone_no": "",
"address": "",
"skype_id": "",
"city": "",
"gender": "Male",
"shoe_size": null,
"user_type": "CompanyAdmin",
"user_image": null,
"remember_token": "H4P7H4Gv5XMjFPjjEDEtrsxp93MMbb4Vt9vut7vaLkJIXemmeWgbkTjzgarM",
"created_at": "2016-07-15 20:22:52",
"updated_at": "2016-07-19 10:06:23",
"deleted_at": null
}, {
"DT_RowId": "row_4",
"id": 4,
"company_id": 3,
"name": "company",
"last_name": "last_name",
"email": "company@gmail.com",
"password": "$2y$10$8rpLCC7mquu2BNoeJVi6OeeA7p9KlTP3QRUc3B\/\/TIX5Vqx0yP7Nm",
"phone_no": "098765433456",
"address": "Iqbal Town, Lahore, Punjab, Pakistan",
"skype_id": "",
"city": "Lahore",
"gender": "",
"shoe_size": null,
"user_type": "CompanyAdmin",
"user_image": null,
"remember_token": null,
"created_at": "2016-07-27 11:55:31",
"updated_at": "2016-07-27 11:55:31",
"deleted_at": null
}],
"options": [],
"files": []
}
我跟随此作为参考data tables with Form Only Data
答案 0 :(得分:0)
您链接的文档适用于DataTable.Editor,它是免费DataTable插件的转售产品。您会注意到您正在使用的示例以此开头:
editor = new $.fn.dataTable.Editor( {
而您发布的代码以此开头:
$('#brands').DataTable({
您正在使用的文档是一种在表单上指定一个充满可编辑值的表的方法,该表不是DataTable功能的一部分。您得到的错误是因为您未能指定数据源,这在调用DataTable()
函数时是必需的。