angularJS中批量提交请求的batch.js(1)

废话不多说,先上代码:

var builder = ODataEFBatchSample.createBatchBuilder();
var changeSet = builder.addChangeSet();


通过post请求向服务器发送数据,请求操作后台的DocumentChangeApplys这张表
changeSet.addRequest({
            requestUri: ControllersUrls.DocumentChangeApplys,
            method: 'POST',
            data: {
                ApplyID: $scope.applyNO,
                DeptID: $scope.applyDeptID,
                DeptName: $scope.applyDept,
                ApplicantType: $scope.ApplicantType,
                ApplyType: $scope.applyType,
                ChangeFileName: fileName,
                RelatedPersonID: "smc\ssss",
                RelatedPersonName: $scope.relatedPerson,
                IsInvolveOtherDept: $scope.isInvolvedDept,
                InvolveOtherDeptID: relatedDeptID,
                InvolveOtherDeptName: relatedDeptName,
                ChangeDescript: $scope.ChangeDescript,
                ApproveStep: $scope.ApproveStep,
                ApproveState: $scope.ApproveState,
                CurrentUserID: DirectorID,
                CurrentUserName: DirectorName
            }
        });

changeSet.addRequest({
            requestUri: ControllersUrls.DocumentSubFlows,
            method: 'POST',
            data: {
                ApplyID: $scope.applyNO,
                CompanyCode: $scope.comanyName.CompanyCode,
                CompanyName: $scope.comanyName.CompanyName,
                FlowID: $scope.flowName.FlowID,
                FlowName: $scope.flowName.FlowName,
                SubFlowID: $scope.subFlowName.SubFlowID,
                SubFlowName: $scope.subFlowName.SubFlowName,
                IsChangeName: $scope.IsChangeName,
                ChangedName: $scope.changeSubFlowName,
                IsChangeFile: $scope.IsChangeFile,
                ChangeState: $scope.ChangeState
            }
        });

changeSet.addRequest({
            requestUri: ControllersUrls.DocumentReferences,
            method: 'POST',
            data: {
                ApplyID: $scope.applyNO,
                DeptID: $scope.applyDeptID,
                DeptName: $scope.applyDept,
                RuleID: $scope.ruleID1,
                RuleName: $scope.ruleName1
            }
        });


获取批量请求。提交成功或者提交失败都会弹出相应的对话框。

var batchRequest = builder.getBatchRequest();
        ODataEFBatchSample.postBatch(batchRequest).then(function (data) {   
            var responses = getResponses(data);
            var IS_Bos = true;
            var ErrMessage = '';
            responses.forEach(function (value, index) {
                if (value.response != null && value.response.statusCode != 200) {
                    IS_Bos = false;
                    ErrMessage = value.message;
                    return;
                }
            });
            if (!IS_Bos) {
                alert('提交失败!\r\n错误原因:' + ErrMessage);
            }
            else {
                //alert('提交成功!');
                //普通JS脚本中无法使用AngularJS方法,需套用
                $timeout(function () {
                    $location.path('/DocCreate');
                });
            }
        });


你可能感兴趣的:(angularJS中批量提交请求的batch.js(1))