Jquery DataTables对象不工作
我是jquery的初学者。。。我下载了这个,但是缺少教程。。。如果有人知道如何正确地做到这一点。。。请帮帮我。。。当我在谷歌上搜索数据表上没有类似对象的问题/帮助时,很难找出原因。。。如果可以的话,我真的需要帮助 警报的输出是正确的。。。 这是我的警报的输出。。。 下面是我在脚本中的代码:Jquery DataTables对象不工作,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我是jquery的初学者。。。我下载了这个,但是缺少教程。。。如果有人知道如何正确地做到这一点。。。请帮帮我。。。当我在谷歌上搜索数据表上没有类似对象的问题/帮助时,很难找出原因。。。如果可以的话,我真的需要帮助 警报的输出是正确的。。。 这是我的警报的输出。。。 下面是我在脚本中的代码: $(document).ready(function () { $.ajax({ url: 'api/mstStudent', data: "", d
$(document).ready(function () {
$.ajax({
url: 'api/mstStudent',
data: "",
dataType: 'json',
success: function (rows) {
//alert(JSON.stringify(rows, null, 1));
var oTable = $('#example').dataTable({
"bProcessing": true,
"sAjaxSource": JSON.stringify(rows, null, 1),
"aoColumns": [
{ "mData": "ID" },
{ "mData": "StudentID" },
{ "mData": "StudentName" },
{ "mData": "Course" },
{ "mData": "YearLevel" },
{ "mData": "Religion" },
{ "mData": "Gender" },
{ "mData": "isLock" }
]
});
}
});
});
这个物体是学生,里面是
StudentID
StudentName
Course
YearLevel
Religion
Gender
isLock
编辑:
这是我使用document.write(JSON.stringify(rows,null,1))时的输出代码>我只是缩短它
[
{
"ID": 1,
"StudentID": "101",
"StudentName": "Jerald Patalinghug",
"Course": "BSIT",
"YearLevel": "1",
"Religion": "Catholic",
"Gender": "Male",
"isLock": true
},
{
"ID": 12,
"StudentID": "102",
"StudentName": "David Laude",
"Course": "BSIT",
"YearLevel": "3",
"Religion": "Catholic",
"Gender": "Female",
"isLock": true
}
]
编辑2
我的控制器。。。我不知道如何在前面添加aaData
private Data.DataClasses1DataContext db = new Data.DataClasses1DataContext();
// GET api/<controller>
public List<Models.mstStudent> Get()
{
var Students = from s in db.mstStudents
select new Models.mstStudent
{
ID = s.ID,
StudentID = s.StudentID,
StudentName = s.StudentName,
Course = s.Course,
YearLevel = s.YearLevel,
Religion = s.Religion,
Gender = s.Gender,
isLock = s.isLock
};
return Students.ToList();
}
private Data.DataClasses1DataContext db=new Data.DataClasses1DataContext();
//获取api/
公共列表Get()
{
var Students=来自db.mststudens中的s
选择新型号。mstStudent
{
ID=s.ID,
StudentID=s.StudentID,
StudentName=s.StudentName,
当然,
YearLevel=s.YearLevel,
宗教=美国的宗教,
性别=s.性别,
isLock=s.isLock
};
返回学生;
}
您的json数据应包含在aaData变量中,如
{
"aaData": [
{
"ID": "1",
"StudentID": "101",
"StudentName": "David",
"version": "BSIT",
"YearLevel": "2",
"Religion": "Catholic",
"Gender": "Male",
"isLock": "true",
},
....// more record objects
]
}
请参见我对数据表并不十分熟悉,但我认为您没有正确使用sAjaxSource。我认为这应该是一个返回JSON对象的URL(因此datatable的创建不会在ajax调用中;我认为Datatables插件可以为您处理这个问题),我尝试以下var source1='{“aaData”:'+JSON.stringify(rows,null,1)+'}'
然后我更改了这个“sAjaxSource”:source1,
,但仍然不工作..当我复制document.write(source1)的输出时它工作
然后我将其粘贴到objects.txt
上,然后更改的“sAjaxSource”:“objects.txt”
。。。IDK如何做到这一点。。。不创建.txt文件