[英]JSON shows in browser, but does not load in the html table with DataTables plugin?
[英]jQuery datatables plugin : Get json from server and displaying table
我需要從服務器獲取JSON並在表中顯示相同的內容。 我無法將JSON對象從服務器映射到DataTable插件。
這是我的JavaScript代碼:
<script type="text/javascript">
var vm = null;
$(function () {
vm = new TestViewModel();
ko.applyBindings(vm);
$(document).ready(function () {
$('#testtable').dataTable({
"sAjaxSource": '@Url.Action("GetFiles", "Home")',
"aoColumns": [
{ "mData": "id" },
{ "mData": "createDate" }
]
});
});
});
這是我的控制器代碼(操作):
[HttpGet]
public ActionResult GetFiles()
{
/*
var result = /*Get object from database*/
*/
return this.JsonSerialize(result)
}
這里需要一些有關如何實現這一目標的指導。 謝謝。
I have model for MVC pattern:
[DataContract]
public class TestViewModelResult : ServiceResult
{
[DataMember(Name = "prototypes")]
public List<PrototypeResult> Prototypes { get; set; }
}
I change script for page:
<script type="text/javascript">
var vm = null;
$(function () {
vm = new TestViewModel();
ko.applyBindings(vm);
$(document).ready(function () {
$('#testtable').dataTable({
"bServerSide": false,
"sAjaxDataProp": "prototypes",
"sAjaxSource": '@Url.Action("GetFiles", "Home")',
"aoColumns": [
{ "mData": "id" },
{ "mData": "createDate" }
]
});
});
});
After that work fine
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.