在使用Web服务调用获得与Tabulator一起使用的第一个工作示例之后,现在我面临着另一个问题,即如何从ajaxResponse返回的响应中访问数据。如何设置特定于AJAX(Tabulator)调用返回的响应的列?我尝试了原始列名,因为它们存在于JSON对象数组中,但无济于事。该列表显示空白行。如果将“ autoColumns:true”设置为属性,则可以看到预期的数据,只是格式和我需要显示给用户的列数都不一样。下面是代码。任何帮助将不胜感激!
本
var usernameval = '*****';
var passwordval = '*****';
var urlHIBRS = 'http://vm-win10-05:8080/Hibrs/hibrs/nibrs/getLatestNibrsHeaders';
var ajaxConfigHIBRS = {
dataType:'json',
data:{},
credentials: 'include',
headers: {
'Accept': 'application/json', //tell the server we need JSON back
'X-Requested-With': 'XMLHttpRequest', //fix to help some frameworks respond correctly to request
'Content-Type': 'application/json; charset=utf-8', //set specific content type
'Authorization': 'Basic ' + btoa(usernameval + ':' + passwordval),
'Access-Control-Allow-Origin': 'http://192.168.0.65', //the URL origin of the site making the request
},
};
var table = new Tabulator('#example-table', {
ajaxConfig:ajaxConfigHIBRS,
ajaxURL:urlHIBRS,
pagination:'local',
paginationSize:100,
paginationDataSent:{
'page':'pageNumber',
'size':'pageSize',
},
/* Paging issues
paginationDataReceived:{
'last_page':'totalPages',
},
*/
layout:'fitColumns',
autoColumns:true,
height:'100%',
placeholder:'No Data Set',
selectable:1,
/*
columns:[ // define the table columns
{title:"Type", field:"response.reporttype"},
{title:"Report No.", field:"reportno"},
{title:"Version", field:"versionnumber"},
{title:"Period", field:"submissionperiod"},
{title:"State Status", field:"statesubmissionstatus"},
{title:"FBI Status", field:"fbisubmissionstatus"},
{title:"Last Submitted", field:"lastsubmittedon", sorter:"date"},
],
*/
ajaxRequesting:function(url, params) {
//alert('url = ' + url);
//url - the URL of the requestac
//params - the parameters passed with the request
},
ajaxResponse:function(url, params, response) {
return response.list;
},
ajaxError:function(error){
//error - the returned error object
alert('error = ' + error);
},
});
答案 0 :(得分:0)
我自己解决了这个问题。后端开发人员发送的字段名称与我期望的不同。对齐名称后,一切就好了。