如何解决Firebase Ionic 5增量和减量
我想用简单的方法在数据库firebase中增加+1和减少-1
increment() {
const i = +1;
this.service.update(i)
}
decrement() {
const i = -1;
this.service.update(i)
}
服务我有简单的代码
update(panel: Panel) {
return this.db.object(`${this.path}/${panel.codeLed}`)
.update(panel);
}
解决方法
我认为您正在寻找increment
运算符,它在常规JavaScript SDK中像这样使用
firebase.database().ref('/path/to/value').update({ firebase.database.ServerValue.increment(1) })
,
我找到了这段代码,对我来说,一切正常
incrementUp(panel: Panel) {
return this.db.object(`${this.path}/${panel.codeLed}/up`)
.query.ref.transaction(ups => {
if (ups === null) {
return ups = 1;
} else {
return ups + 1;
}
});
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。