全部, 我在这里有一个有趣的可能只是我做错了所以我可以使用你的帮助。
我有一个功能...
function updateStatusNStage(status, stage) {
var dfdStatusUpdate = new $.Deferred(function() {
var reqList = modCommon.SharePointContext.get_web().get_lists().getByTitle('RequestDetails'),
uListItem = reqList.getItemById(ProjectContext.ItemID);
uListItem.set_item('Stage', stage);
uListItem.set_item('Status', status);
uListItem.update();
modCommon.SharePointContext.executeQueryAsync(onQuerySNSWriteSucceeded, onQuerySNSWriteFailed);
function onQuerySNSWriteSucceeded() {
modCommon.ShowMessage('Stage updated on ' + ProjectContext.ItemID + ' to status of ' + status + ' and stage of ' + stage);
}
function onQuerySNSWriteFailed(sender, args) {
alert('Stage Update Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
});
return dfdStatusUpdate.promise();
}
当我执行以下操作时,只有第一个工作。在我看来,这个承诺已经在第一次通话中实现了,所以我该怎么做?
function stageCompleteCheck(stage) {
var dfd = gheaSPDataAccess.GetDataFromSP("ReviewerAssignment",
"<View><Query><Where><And><Eq><FieldRef Name='RequestID' /><Value Type='Number'>" +
modARBRequest.ProjectContext.ItemID + "</Value></Eq><Eq><FieldRef Name='Stage' /><Value Type='Text'>" +
stage + "</Value></Eq></And></Where></Query><ViewFields><FieldRef Name='ID' /><FieldRef Name='RequestID' />" +
"<FieldRef Name='ReviewerEmail' /><FieldRef Name='CategoryID' /><FieldRef Name='Comments' /><FieldRef Name='Result' />" +
"<FieldRef Name='Modified' /><FieldRef Name='Stage' /></ViewFields></View>");
dfd.done(function (reviewsSubmitted) {
if (modCommon.IsRealValue(reviewsSubmitted)) {
var reviewersAssignedCnt = $.grep(reviewsSubmitted, function (obj) {
return obj.Result !== 'NoResult';
});
if (reviewsSubmitted.length >= reviewersAssignedCnt.length) {
// all reviews are in
if (stage === 'Voting') {
var dfdStatusUpdate = modARBRequest.UpdateStatusNStage('Open', 'Voting Completed'); // finalize voting
dfdStatusUpdate.done(function() {
var updStatus = modARBRequest.UpdateStatusNStage('Open', 'Review Initiated'); // initiate review
updStatus.done(function () {
alert('hit second update');
});
});
}
if (stage === 'Review') {
var dfdStatusUpdate = modARBRequest.UpdateStatusNStage('Open', 'Review Completed'); // finalize review
dfdStatusUpdate.done(function() {
modARBRequest.UpdateStatusNStage('Closed', 'Final'); // finalize request ?? Do you want a pre-final status to review the decision?
});
}
}
}
});
不起作用的部分如下......
if (stage === 'Voting') {
var dfdStatusUpdate = modARBRequest.UpdateStatusNStage('Open', 'Voting Completed'); // finalize voting
dfdStatusUpdate.done(function() {
var updStatus = modARBRequest.UpdateStatusNStage('Open', 'Review Initiated'); // initiate review
updStatus.done(function () {
alert('hit second update');
});
});
}
我感谢您在这一方面给予我的任何帮助。
答案 0 :(得分:0)
发现我没有在UpdateStatusNStage函数中添加.resolve()。 DOH!
function updateStatusNStage(status, stage) {
var dfdStatusUpdate = new $.Deferred(function() {
var reqList = modCommon.SharePointContext.get_web().get_lists().getByTitle('RequestDetails'),
uListItem = reqList.getItemById(ProjectContext.ItemID);
uListItem.set_item('Stage', stage);
uListItem.set_item('Status', status);
uListItem.update();
modCommon.SharePointContext.executeQueryAsync(onQuerySNSWriteSucceeded, onQuerySNSWriteFailed);
function onQuerySNSWriteSucceeded() {
modCommon.ShowMessage('Stage updated on ' + ProjectContext.ItemID + ' to status of ' + status + ' and stage of ' + stage);
dfdStatusUpdate.resolve();
}
function onQuerySNSWriteFailed(sender, args) {
alert('Stage Update Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
dfdStatusUpdate.reject();
}
});
return dfdStatusUpdate.promise();
}