Model view controller 如何暂停控制器直到服务器返回响应? save=()=>{ 对于(var j=0;j{ 返回; }); } }

Model view controller 如何暂停控制器直到服务器返回响应? save=()=>{ 对于(var j=0;j{ 返回; }); } },model-view-controller,typescript,Model View Controller,Typescript,大宗报价 它仅暂停最后一个值4个post 在ajax调用中不能真正暂停控制器。您可以有一个回调方法来处理返回的响应 这条线错了 save = () => { for (var j = 0; j < this.templatetypes.length; j++) { this.template = this.templatetypes[j]; this.smsTemplate.Template_Ty

大宗报价 它仅暂停最后一个值4个post


在ajax调用中不能真正暂停控制器。您可以有一个回调方法来处理返回的响应

这条线错了

save = () => {
            for (var j = 0; j < this.templatetypes.length; j++) {
                this.template = this.templatetypes[j];
                this.smsTemplate.Template_Type_LSeq = this.template.value;
                this.smsTemplate.SmsCode = this.template.smsCode;
                this.smsTemplate.SmsName = this.template.smsName;
                this.smsTemplate.SmsMessageTemplate = this.template.smsFormat;
                this.smsTemplateSvc.postSmsTemplate(this.smsTemplate).then(() => {
                    return;
                });
            }                      
        }
您正在执行
.then()
承诺中的返回,因此只要
.postsTemplate()
解析,它就会执行返回并立即退出

$http有更多关于它的信息

这里有一个很好的例子:

 this.smsTemplateSvc.postSmsTemplate(this.smsTemplate).then(() => {
      return;
 });