我正在使用sAjaxSource
從我的彈簧控制器獲取數據,從而給出json響應。 像這樣GSON with DataTables彈簧mvc爲空數據
[
{
"id":20009,
"title":"1914 tran by H. Rackham",
"description":"\"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charmces ",
"username":"nessudi",
"datecreated":"Apr 22, 2014 10:39:24 AM"
},
{
"id":20008,
"title":"The standard Lorem Ipsum passage, used since the 1500s",
"description":"\"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\"",
"username":"naai",
"datecreated":"Apr 22, 2014 10:38:46 AM"
},
{
"id":20065,
"title":"Where to get Lorem Ipsum",
"description":"Therpetition, injected humour, or non-characteristic words etc.",
"username":"nensi",
"datecreated":"Apr 22, 2014 10:37:34 AM"
},
{
"id":20056,
"title":"What is Lorem Ipsum",
"description":"Lorrinter took a galley of type and scrambled it to make a type specimen book. ",
"username":"xyz",
"datecreated":"Apr 22, 2014 10:28:39 AM"
}
]
雖然當沒有數據的數據表中顯示「正在加載......」消息。
我讀過其他職位,建議發送空數組與「{aaData:[]}」..但我使用 「sAjaxDataProp」:「」..我的數據屬性爲空..我如何處理這個(事情?我在java中使用gson庫。
這是我的控制器
@RequestMapping(value="/theurl", method = RequestMethod.GET)
public @ResponseBody String somemethod(){
List<someobject> listobjs = this.someService.getobjsList();
if(listobjs != null){
Collections.sort(listobjs, Collections.reverseOrder());
}
return gson.toJson(listobjs);
}
這裏是我的DataTable創建
$("#myTable").dataTable({
"bPaginate": true,
"sAjaxSource": "/theurl",
"sAjaxDataProp": "",
"oLanguage": {
"sEmptyTable": "My Custom Message On Empty Table"
},
"iDisplayLength": 5,
"bSort" : false,
"aoColumnDefs" : [
{"aTargets": [0],
"mRender" : function (data, type, full){
return '<input style="float:left; margin: 0 auto; width: 100%;" class="selected" type="checkbox" value="' + data + '">';
}
}
],
"aoColumns" : [{"mData" : "id"},
{"mData" : "title"},
{"mData" : "description"},
{"mData" : "datecreated"}],
"fnInitComplete": function(oSettings, json){
//I do something here after init.
}
});
它完美罰款時,有列表中的一些數據,但如果該列表是空的DataTable中只顯示「加載」消息,我得到類型錯誤:無法處理瀏覽器控制檯錯誤中的空例外。 我已經通過編寫一些jquery代碼來替換「Loading ...」消息來臨時修復它。請指導。