Firebase - 推送到推送的数据
Firebase - Push to pushed data
这是我的数据
{
"deck" : {
"-JkpwAnieKjQVsdtPD4m" : {
"deck" : "Deck 1",
"user" : "simplelogin:1"
},
"-Jkq4unexm-qwhO_U2YO" : {
"deck" : "Deck 2",
"user" : "simplelogin:1"
},
"-Jkq5-II1q5yM6w3ytmG" : {
"deck" : "Deck 3",
"user" : "simplelogin:6"
},
"-Jks5mbMHmPB9MwnnOCj" : {
"deck" : "Deck 4",
"user" : "simplelogin:1"
}
}
}
如果我要补充:
cards: {
"-GeneratedKey":{
"title":"foo",
"text":"bar",
}
}
用甲板 "Deck 2" 说物品,我如何 select 将那个物体推到它上面。最终结果将是:
{
"deck" : {
"-JkpwAnieKjQVsdtPD4m" : {
"deck" : "Deck 1",
"user" : "simplelogin:1"
},
"-Jkq4unexm-qwhO_U2YO" : {
cards: {
"-GeneratedKey":{
"title":"foo",
"text":"bar",
}
}
"deck" : "Deck 2",
"user" : "simplelogin:1"
},
"-Jkq5-II1q5yM6w3ytmG" : {
"deck" : "Deck 3",
"user" : "simplelogin:6"
},
"-Jks5mbMHmPB9MwnnOCj" : {
"deck" : "Deck 4",
"user" : "simplelogin:1"
}
}
}
这是我尝试过的:
deckRef.orderByChild('deckName').equalTo('Deck 2').push({
card: {
title: 'foo',
text: 'bar'
}
});
但这只是返回了一个错误。我该怎么做才能做到这一点?
deckRef.orderByChild('deckName').equalTo('Deck 2')
returns 查询,不是参考。一个查询可以匹配多个节点。即使在您的情况下它只匹配一个,您也需要先将该节点捕获到一个 ref 中才能 push
到它。
var query = deckRef.orderByChild('deckName').equalTo('Deck 2');
query.once('child_added', function(snapshot) {
snapshot.ref().child('cards').push({
title: 'foo',
text: 'bar'
});
});
这是我的数据
{
"deck" : {
"-JkpwAnieKjQVsdtPD4m" : {
"deck" : "Deck 1",
"user" : "simplelogin:1"
},
"-Jkq4unexm-qwhO_U2YO" : {
"deck" : "Deck 2",
"user" : "simplelogin:1"
},
"-Jkq5-II1q5yM6w3ytmG" : {
"deck" : "Deck 3",
"user" : "simplelogin:6"
},
"-Jks5mbMHmPB9MwnnOCj" : {
"deck" : "Deck 4",
"user" : "simplelogin:1"
}
}
}
如果我要补充:
cards: {
"-GeneratedKey":{
"title":"foo",
"text":"bar",
}
}
用甲板 "Deck 2" 说物品,我如何 select 将那个物体推到它上面。最终结果将是:
{
"deck" : {
"-JkpwAnieKjQVsdtPD4m" : {
"deck" : "Deck 1",
"user" : "simplelogin:1"
},
"-Jkq4unexm-qwhO_U2YO" : {
cards: {
"-GeneratedKey":{
"title":"foo",
"text":"bar",
}
}
"deck" : "Deck 2",
"user" : "simplelogin:1"
},
"-Jkq5-II1q5yM6w3ytmG" : {
"deck" : "Deck 3",
"user" : "simplelogin:6"
},
"-Jks5mbMHmPB9MwnnOCj" : {
"deck" : "Deck 4",
"user" : "simplelogin:1"
}
}
}
这是我尝试过的:
deckRef.orderByChild('deckName').equalTo('Deck 2').push({
card: {
title: 'foo',
text: 'bar'
}
});
但这只是返回了一个错误。我该怎么做才能做到这一点?
deckRef.orderByChild('deckName').equalTo('Deck 2')
returns 查询,不是参考。一个查询可以匹配多个节点。即使在您的情况下它只匹配一个,您也需要先将该节点捕获到一个 ref 中才能 push
到它。
var query = deckRef.orderByChild('deckName').equalTo('Deck 2');
query.once('child_added', function(snapshot) {
snapshot.ref().child('cards').push({
title: 'foo',
text: 'bar'
});
});