[英]how can i get single value from firebase realtime database for ionic
async incrementTuts(key) {
let newData= {'tutsApplied':this.tutsApplied+1}
let newInfo = firebase.database().ref('thisis/'+this.route.snapshot.paramMap.get('key')).update(newData);
}
I want to increment tutsApplied on firebase realtime database using ionic 4. how can i acheive that.我想使用 ionic 4 在 firebase 实时数据库上增加 tutsApplied。我怎么能做到这一点。
Corrected image:更正的图像:
update:更新:
i have used我用过了
let key = this.route.snapshot.paramMap.get('key');
let ref = firebase.database().ref(`thisis/${key}/tutsApplied`);
ref.transaction((current) => {
return (current || 0) + 1;
});
but new field is created under undefined as shown in image.但是新字段是在 undefined 下创建的,如图所示。 i dont want to create new field.
我不想创建新领域。 and how can i print current value in console?
以及如何在控制台中打印当前值?
It sounds like you're looking to write a new value for a property based on its current value.听起来您希望根据属性的当前值为其编写新值。 To do that, you'd use a transaction .
为此,您需要使用交易。
Something like:就像是:
let key = this.route.snapshot.paramMap.get('key');
let ref = firebase.database().ref(`thisis/${key}/tutsApplied`);
ref.transaction((current) => {
return (current || 0) + 1;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.