this.$('#tblRoles').dataTable({
"bAutoWidth": true,
"aoColumns": [
{ "mDataProp": "Code", },
{ "mDataProp": "Title", }
],
"bServerSide": true,
"sAjaxSource": '/FunzHouse/Roles.aspx/Menu',
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "POST",
"contentType": "application/json; charset=utf-8",
"url": sSource,
"data": '',
"success":
function (data) {
fnCallback(JSON.stringify(data.d));
}
});
}
});
我在浏览器中看到数据正确返回,但是为什么它不能填充到jquery数据表中?数据示例如下 [{“Code”:“0000”,“Title”:“Home”},{“Code”:“1000”,“Title”:“Profiles management”}]“
data:
Object {d: Array[2]}
d: Array[2]
0: Object
1: Object
}
data.d: [对象,对象]
更新1:
this.$('#tblRoles').dataTable({
"bAutoWidth": true,
"bServerSide": true,
"aoColumns": [
{
"sTitle": "test", "mDataProp": "Code"
},
{
"sTitle": "test", "mDataProp": "Title"
}
],
"sAjaxSource": '/FunzHouse/Roles.aspx/Menu',
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "POST",
"contentType": "application/json; charset=utf-8",
"url": sSource,
"data": '',
"success":
function (data) {
debugger;
var feed = JSON.parse(JSON.stringify(data.d));
fnCallback(_.flatten(feed));
}
});
}
});
不知道为什么它仍然没有工作,继续得到未定义的长度,实际上我做错了什么?
更新2: 好吧,我改变了另一种方法,而不是使用sAjax,它工作得很好,猜测我不能使用sAjax来填充数据
generateMenu: function () {
var that = this;
var _RolesMenu = new RolesMenu();
_RolesMenu.fetch({
type: "POST",
data: '',
contentType: "application/json; charset=UTF-8",
success: function (Menu) {
that.appendMenu(Menu);
}
});
},
appendMenu: function (data) {
var that = this;
var feed = JSON.parse(JSON.stringify(data));
var oTable = $('#tblRoles').dataTable({
"bDestroy": true,
"bAutoWidth": true,
"aoColumns": [
{ "sTitle": "Code", "mDataProp": "Code", },
{ "sTitle": "Title", "mDataProp": "Title", },
],
sAjaxSource: "",
sAjaxDataProp: "",
fnServerData: function (sSource, aoData, fnCallback) {
fnCallback(_.flatten(feed[0]));
},
});
},