我正在努力从加入中返回一个值。我认为问题在于放置" return"一句话,但我找不到任何文件。
我在代码中添加了一些注释来更好地解释我的问题。
this.databaseService.getAlbumName(0).then(result =>{
return result;
}).then(snap => {
//snap return what I want so albumName.
//Problem start when getPhotosFromAlbum(snap) kicks is.
return this.databaseService.getPhotosFromAlbum(snap).then(photoResult => {
//Am I returning value(array) from getPhotosFromAlbum(snap) in correct place?
return photoResult;
}).then(snapp => {
//this part if just to display photoResult which is currently equal
//to [Object object]
console.log('array of photos: ' + snapp);
})
和
public getPhotosFromAlbum(albumName: string): any{
//getting access to all Photos in album
let photosInAlbum = firebase.database().ref('PhotosInAlbum' + '/' + albumName)
return photosInAlbum.once('value', snap => {
let photoRef = this.databaseRef.child('Photo');
photoRef.once('value', photoSnap => {
let photos = photoSnap.val();
//creating an accessible array
let keys = Object.keys(photos);
var k = [];
for(var i = 0; i < keys.length; i++){
k.push(keys[i]);
}
console.log('From get Function: ' + k);
return k;
})
})
}
答案 0 :(得分:0)
就我所见,你的getPhotosFromAlbum
并没有回复承诺。
public getPhotosFromAlbum(albumName: string): any{
let photosInAlbum = firebase.database().ref('PhotosInAlbum' + '/' + albumName)
return photosInAlbum.once('value').then(snap => {
let photoRef = this.databaseRef.child('Photo');
return photoRef.once('value').then(photoSnap => {
let photos = photoSnap.val();
//creating an accessible array
let keys = Object.keys(photos);
var k = [];
for(var i = 0; i < keys.length; i++){
k.push(keys[i]);
}
return k;
})
})
}
最内心的倾听者似乎是一个非常复杂的方式:
return photoRef.once('value').then(photoSnap => {
return Object.keys(photoSnap.val());
})