【发布时间】:2014-09-06 07:22:50
【问题描述】:
我在将 Firebase 调用函数的返回值分配给我的全局变量时遇到问题。这是我的功能:
function getThePushNameById( path , id ){
path.once( 'value', function( data ){
if( data.child('id').val() != id ){
data.forEach( function( newData ){
var base = new Firebase( path.child( newData.name() ).toString() );
getThePushNameById( base, id );
})
}else{
//finishes the function when path is founded - returns the value
return path.name();
}
})
}
这是我设置请求的另一个文件:
var base = new Firebase(path/to/my/base);
var output = getThePushNameById( base , 2 )
console.log(output);
所以我的问题是console.log 不会等待output 被定义,而是自行运行并记录undefined。我的问题是,如果有人知道我怎样才能让console.log 等待价值?
【问题讨论】:
标签: javascript firebase firebasesimplelogin