Firebase删除查询结果 [英] Firebase delete query result
本文介绍了Firebase删除查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b $我有下面的代码,我试图删除测验记录b var authref = new Firebase(https://.firebaseio.com);
var authData = authref.getAuth();
var ref = new Firebase(https://.firebaseio.com/quiz);
ref.orderByChild(uid)。equalTo(authData.uid).on(value,function(snapshot){
snapshot.forEach(function(data){
var record = data.val();
if(record [name] == name)
{
ref.remove(record.ref());
}
});
});
我想删除属于已验证用户的测验具有与传递给包装器函数相同的名称。
我知道我需要传递测验的引用URL,但我不确定如何获取该ID是由Firebase自动生成的。
以下是我的数据布局示例:
quiz
-KDATEVU4fU5OF55fCbP
-KDOIReUla7Fj1K62x7S
-KDOJ-oI0JYmCdWrqrx_
-KDPr7deQ5BHQcTwQ_cG
名称:question
密码:9876
问题
-KDPr82WcFw-jfuPz3T1
0
答:s
尝试:0
正确:0
qtext:a
wrong1:d
wrong2:f
wrong3:g
uid:1f72bd29-967c-446d-a6b9-37ec9de540e0
如果有人能帮我解决这个问题,我会很感激。 b
解决方案
我刚才知道了。
var authref = new Firebase(https://.firebaseio .COM);
var authData = authref.getAuth();
var ref = new Firebase(https://.firebaseio.com/quiz); ($)$ b $ ref.orderByChild(uid)。equalTo(authData.uid).on(value,function(snapshot){
snapshot.forEach(function(data){
var record = data.val();
if(record [name] == name)
{
ref.child(data。 key())。remove();
}
});
});
I have the following code that I'm trying to remove quiz records with:
var authref = new Firebase("https://.firebaseio.com");
var authData = authref.getAuth();
var ref = new Firebase("https://.firebaseio.com/quiz");
ref.orderByChild("uid").equalTo(authData.uid).on("value", function(snapshot) {
snapshot.forEach(function(data) {
var record = data.val();
if(record["name"] == name)
{
ref.remove(record.ref());
}
});
});
I want to delete a quiz that belongs to the authenticated user and has the same name that is passed to the wrapper function.
I know that I need to pass the reference URL of the quiz, but I'm not sure how to get the ID because it's auto-generated by Firebase.
Below is an example of my data layout:
quiz
-KDATEVU4fU5OF55fCbP
-KDOIReUla7Fj1K62x7S
-KDOJ-oI0JYmCdWrqrx_
-KDPr7deQ5BHQcTwQ_cG
name: "question"
passcode: "9876"
questions
-KDPr82WcFw-jfuPz3T1
0
ans: "s"
attempts: 0
correct: 0
qtext: "a"
wrong1: "d"
wrong2: "f"
wrong3: "g"
uid: "1f72bd29-967c-446d-a6b9-37ec9de540e0"
I'd be really grateful if anyone could help me out with this.
解决方案
I've just figured it out. I should have RTFM.
var authref = new Firebase("https://.firebaseio.com");
var authData = authref.getAuth();
var ref = new Firebase("https://.firebaseio.com/quiz");
ref.orderByChild("uid").equalTo(authData.uid).on("value", function(snapshot) {
snapshot.forEach(function(data) {
var record = data.val();
if(record["name"] == name)
{
ref.child(data.key()).remove();
}
});
});
这篇关于Firebase删除查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文