我接受数据到变量中,我希望变量成为URL的一部分,指向Firebase数据库中我想要检索数据的位置。
这是我的代码:
function Call()
{
var dbref=new Firebase("https://dataretrievaltest-28983.firebaseio.com/EmployeeDB/EInfo").orderByKey();
var login=localStorage.getItem("Email");
console.log("Passed Email"+login);
dbref
.once("value")
.then
(
function(snapshot)
{
snapshot.forEach
(
function(childsnapshot)
{
var data = childsnapshot.val();
var emailval=data.Email;
if(login==emailval)
{
console.log(data.EID);
Eidval=data.EID;
}
}
);
}
);
var dsRef=new Firebase("https://dataretrievaltest-28983.firebaseio.com/EmployeeDB/EDetail/EmployeeDB/EDetail/"+Eidval);
dsRef
.once("value")
.then
(
function(snapshot)
{
//console.log(snapshot.val());
snapshot.forEach
(
function(childsnapshot)
{
var data = childsnapshot.val();
console.log(data);
}
);
}
);
}
以上代码无效,附加/EDetail/"+Eidval
未生成任何o / p
Eidval
被定义为全局变量:
<body>
<input type="button" value="Pull" id="btpull" onclick="Call()">
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<script src="https://cdn.firebase.com/v0/firebase-simple-login.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.6/firebase.js"></script>
<script>
var Eidval=0;
var config = {
apiKey: "AIzaSyA2LEx_3C0qPI75AexMPhCfZCxnVV-MVbU",
authDomain: "dataretrievaltest-28983.firebaseapp.com",
databaseURL: "https://dataretrievaltest-28983.firebaseio.com",
storageBucket: "dataretrievaltest-28983.appspot.com",
messagingSenderId: "572246196580"
};
firebase.initializeApp(config);
</script>
输出:
Passed Emailchris@page.com Phase1work.html:51 153
答案 0 :(得分:0)
控制台记录您的Eidval
并检查您是否在语句级别可以看到该变量。
答案 1 :(得分:0)
我在代码(childsnapshot)中移动了代码并且它有效!