我正在使用Javascript中的以下函数从SharePoint上两个单独的列表中提取数据,并将结果数据传递给另一个函数。我花了过去几个小时尝试调试此功能,并出现以下错误:
jQuery.Deferred异常:不允许重复的参数名称 此上下文SyntaxError:在此不允许重复的参数名称 语境 在Array。
被告知错误发生在此行:
successFunction(RecordResponse, RecordAmountResponse)
奇怪的是,它确实通过了两个.done函数并输出了它们各自的检查标志,但是我知道我无法更改.then(function(){})中的参数,否则我的successFunction将不会收到响应所需的数据。
这是我正在调用的函数:
function getReportData(strRecordQuery, strRecordAmountQuery, successFunction, failFunction) {
// Use promise methods to run getListQuery from both tblRecord and tblRecordData
var RecordDataInfo = $.Deferred();
var RecordAmountDataInfo = $.Deferred();
var dfdRecordDataFiles;
var dfdRecordAmountDataFiles;
dfdRecordDataFiles = getListQuery('lstRecord', strRecordQuery, true);
dfdRecordAmountDataFiles = getListQuery('lstRecordAmount', strRecordAmountQuery, true);
dfdRecordDataFiles.done(function(RecordDataResponse) {
console.log("dfdRecordDataFiles.done");
RecordDataInfo.resolve(RecordDataResponse);
});
dfdRecordAmountDataFiles.done(function(RecordAmountDataResponse) {
console.log("dfdRecordAmountDataFiles.done");
RecordAmountDataInfo.resolve(RecordAmountDataResponse);
});
dfdRecordDataFiles.fail(function(error) {
console.log("dfdRecordDataFiles.fail");
console.log("ResponseText: " + error.responseText);
console.log(JSON.stringify(error));
RecordDataInfo.fail(error);
});
dfdRecordAmountDataFiles.fail(function(lerror) {
console.log("dfdRecordAmountDataFiles.fail");
console.log("ResponseText: " + lerror.responseText);
console.log(JSON.stringify(lerror));
RecordAmountDataInfo.fail(lerror);
});
$.when(RecordDataInfo, RecordAmountDataInfo)
.then(function(RecordResponse, RecordAmountResponse) {
successFunction(RecordResponse, RecordAmountResponse)
}, function(error, lerror) {
failFunction(error, lerror);
});
};
由于我已经厌倦了盯着它看而又不明白这一点,我能否再给我第二眼的帮助呢?
修改
我已根据建议修改了代码,但收到类似错误:
function getListQuery(listName, queryString) {
// REST Call
return $.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('" + listName + "')/items?" + queryString,
type: "GET",
headers: { ACCEPT: "application/json;odata=verbose" }
});
};
function getReportData(strRecordQuery, strRecordAmountQuery, strRecordPersonnelQuery) {
return $.when(getListQuery('lstRecord', strRecordQuery, true), getListQuery('lstRecordAmount', strRecordAmountQuery, true), getListQuery('lstRecordPersonnel', strRecordPersonnelQuery, true))
};
function setReportQueries(Yr0, Yr1, Yr2, Yr3, Yr4) {
// Specific to the report
strRecordQuery = "$select=ID,RecordName";
strRecordAmountQuery = "$select=ID,Parameter1,Year,Amount&$filter=(Year eq '" + Yr0 + "') or (Year eq '" + Yr1 +
"') or (Year eq '" + Yr2 + "') or (Year eq '" + Yr3 + "') or (Year eq '" + Yr4 + "')";
strRecordPersonnelQuery = "$select=ID, Parameter1&$filter=(Year eq '" + Yr0 + "') or (Year eq '" + Yr1 +
"') or (Year eq '" + Yr2 + "') or (Year eq '" + Yr3 + "') or (Year eq '" + Yr4 + "')";
getReportData(strRecordQuery, strRecordAmountQuery, strRecordPersonnelQuery).then(loadReportTables);
};
function loadReportTables(RecordData, RecordAmountData, RecordPersonnelData) {
console.log("Enter loadReportTables()");
/* Do Stuff */
}
我得到的错误是:
jQuery.Deferred异常:不允许重复的参数名称 此上下文SyntaxError:在此不允许重复的参数名称 语境 在l(https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js:2:29375) 在c(https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js:2:29677) 未定义