Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在TypeScript中解析链式承诺中的上承诺_Javascript_Typescript_Promise - Fatal编程技术网

Javascript 如何在TypeScript中解析链式承诺中的上承诺

Javascript 如何在TypeScript中解析链式承诺中的上承诺,javascript,typescript,promise,Javascript,Typescript,Promise,我在提供程序中有此方法: get() { var debugOptionUseLocalDB = 0, prodata = [], serverAttempts = 0; return new Promise((resolve, reject) => { if (this.connectionStatus.f() === 'online') { return this.getDBfileXHR(thi

我在提供程序中有此方法:

get() {
    var debugOptionUseLocalDB = 0,
        prodata = [],
        serverAttempts = 0;

    return new Promise((resolve, reject) => {
        if (this.connectionStatus.f() === 'online') {
            return this.getDBfileXHR(this.dbUrl(), serverAttempts)
                .then(function (data) { // success
                    console.log('-normal XHR request succeeded.');
                    resolve(data);
                })
                .catch((reason)=> {
                    ...
                })
        }
        else{
            ...
        }
    })
}
我从app.component.ts调用它:

           this.updateProDB.get()
                .then( () => {
                    let prodata = this.storageService.get('prodata');
                    this.imagesService.manageStoredImageUrlsNew(prodata);
                })
                .catch((reason)=> {
                    console.error('imagesUrl have not been managed, because updateProDb failed with error:' + reason)
                });
我确信
this.getDBfileXHR()
会解析,因为我在控制台中看到“-normal XHR request successed.”。但是,̀this.updateProDB.get()
拒绝,我们转到
.catch()̀`


解析(数据)解析get()的正确方法?

拒绝错误是什么?一种选择是不使用
新承诺((resolve,reject)=>{…})
而是直接
返回这个.getDBfileXHR(this.dbUrl(),servertruments)
是的,但是我需要包装,为了清晰起见,我删除了一些代码,但是有一些逻辑。实际上,我用
返回这个.getDBfileXHR(this.dbUrl(),serverAttempts)。然后(函数(数据){//success
替换为
返回这个.getDBfileXHR(this.dbUrl(),serverAttempts)。然后((数据)=>{//success
,它现在似乎工作了……奇怪吗?get()使用数据解析,但调用方忽略结果。这是故意的吗?此外,
this.storageService.get(…
同步运行吗?如果不是,当传递到
manageStoredImageUrl()时,prodData将
null
很好,你简化了这篇文章的代码,但是你可能删除了太多。是的,storageService是同步运行的。是的,我不需要调用者中的结果,所以这是有意的,谢谢你的提醒。确实,我可能删除了太多,但我注意到,代码太多,帮助往往会少。因此解决方法应该是显然是在一个箭头函数中,但是当您不能使用=>时,如何管理它呢?