我可以使用 DataTables.net 静态绑定,如下所示:
<script type="text/javascript">
$(document).ready(function () {
$('#testDatatable').dataTable({
"aaData": [
["Ibrahim", 55],
["Asif", 20],
["Shariful", 70],
["John", 55],
["Doe", 40],
["Nazmul", 30],
["Jane", 15],
["Ershad", 10],
["Yusuf", 44],
["Bill", 22],
["Steve", 18]
]
,
"aoColumns": [
{ "sTitle": "Name" },
{ "sTitle": "Age" }
]
});
});
</script>
但是对于 prop aaData,我想从 Web 服务中获取数据。如下所示:
<script type="text/javascript">
$(document).ready(function () {
$('#testDatatable').dataTable({
"aaData": $.getJSON('http://localhost:9183/Service.svc/GetCustomer')
,
"aoColumns": [
{ "sTitle": "Name" },
{ "sTitle": "Age" }
]
});
});
</script>
我的服务如下所示:
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public List<Customer> GetCustomer()
{
List<Customer> customers = new List<Customer>();
customers.Add(new Customer { Name = "Ibrahim", Age = 10 });
customers.Add(new Customer { Name = "John Doe", Age = 20});
return customers;
}
这不起作用。它表明没有找到任何记录。有人请告诉我我有哪些选择或哪里出错了。任何建议都受到高度赞赏。