ES 2015 Promise.all没有解决

时间:2017-08-22 07:03:03

标签: javascript angular ecmascript-6 nativescript

我使用的是嵌套Promise.all,但最后Promise.all并未解析。这是我的代码:

        let eventPromises = [];  
        for(let event of events) {
            event.customProperties = {};

            let localPromises = [];
            //map
            let locationPromise = this.getEventLocation(event.latitude, event.longitude)
            .then((address: LocationAddress) => {
                if(address) {
                    event.customProperties.address = address;
                }
                console.log('----------location promise-----------')
                return event;
            }); 
            localPromises.push(locationPromise); 
            //weather
             let weatherPromise = this.getWeather(event.latitude, event.longitude)
             .then(weatherInfo => {
                 event.customProperties.weather = weatherInfo;
            });
            localPromises.push(weatherPromise);

            let eventPromise = Promise.all(localPromises).then(() => {
                this.data.push(event);
                console.log('----------localPromises done-----------')
                return event;
            });                    
            eventPromises.push(eventPromise);
        }
        console.dir(eventPromises); //The __zone_symbol__state is always show null

        Promise.all(eventPromises).then(() => {
            console.log('----------------All events are done--------------------')
            //Its neveer called
        });

我想在eventPromises解析后执行代码。

enter image description here

0 个答案:

没有答案