两次调用同一个函数,第二次没有触发

Call the same function twice and second one doesn't fire

全部, 我这里有一个有趣的可能只是我做错了什么所以我可以得到你的帮助。

我有一个功能...

    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');
                        });
                    });
                }

我很感激你能在这方面给我的任何帮助。

发现我没有在 UpdateStatusNStage 函数中添加 .resolve()。卫生部!

    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();
}