我正在使用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 ...”消息来临时修复它。请指导。