Firebase 如果 child 等于某个值,则删除该条目
Firebase If child is equal to something remove that entry
我想做的是例如我从数据库中提取 pixidata,用 it.if 计算结果进行一些计算,例如 > 然后 10,我想删除那个 pixilats,pixilongs 键。
这种代码怎么写?我正在使用 angularfire。就像了解 child 一样,我需要删除密钥。
这是我获取数据的方式:
this.pixiData = this.db.list(`/pixidata/`).valueChanges();
this.pixiData.take(1).subscribe(pixi => {
let pixidata = pixi.map(this.getObjectWithoutKnowingKey)
this.pixiData=pixidata;
获取对象函数:
getObjectWithoutKnowingKey(data) {
let objects = [];
for (var propName in data) {
if (data.hasOwnProperty(propName)) {
objects.push(data[propName]);
}
}
return objects;
}
谢谢
我将简单地引用 angularfire2
文档中关于 Retrieving data as lists
的相关部分
valueChanges()
[…]
Why would you use it? - When you just need a list of data. No snapshot
metadata is attached to the resulting array which makes it simple to
render to a view.
When would you not use it? - When you need […] the key of each snapshot for data
manipulation methods. This method assumes you either are saving the
key for the snapshot data or using a "readonly" approach.
snapshotChanges()
[…]
Why would you use it? - When you need a list of data but also want to
keep around metadata. Metadata provides you the underyling
DatabaseReference and snapshot key. Having the snapshot's key around
makes it easier to use data manipulation methods. […]
请尝试手动保存密钥或使用 snapshotChanges()
而不是 valueChanges()
来检索密钥。
我想做的是例如我从数据库中提取 pixidata,用 it.if 计算结果进行一些计算,例如 > 然后 10,我想删除那个 pixilats,pixilongs 键。
这种代码怎么写?我正在使用 angularfire。就像了解 child 一样,我需要删除密钥。
这是我获取数据的方式:
this.pixiData = this.db.list(`/pixidata/`).valueChanges();
this.pixiData.take(1).subscribe(pixi => {
let pixidata = pixi.map(this.getObjectWithoutKnowingKey)
this.pixiData=pixidata;
获取对象函数:
getObjectWithoutKnowingKey(data) {
let objects = [];
for (var propName in data) {
if (data.hasOwnProperty(propName)) {
objects.push(data[propName]);
}
}
return objects;
}
谢谢
我将简单地引用 angularfire2
文档中关于 Retrieving data as lists
valueChanges()
[…]
Why would you use it? - When you just need a list of data. No snapshot metadata is attached to the resulting array which makes it simple to render to a view.
When would you not use it? - When you need […] the key of each snapshot for data manipulation methods. This method assumes you either are saving the key for the snapshot data or using a "readonly" approach.
snapshotChanges()
[…]
Why would you use it? - When you need a list of data but also want to keep around metadata. Metadata provides you the underyling DatabaseReference and snapshot key. Having the snapshot's key around makes it easier to use data manipulation methods. […]
请尝试手动保存密钥或使用 snapshotChanges()
而不是 valueChanges()
来检索密钥。