我有一个推送数据的功能,另外两个属性必须被推送/更新/存储到同一个键。有percentMale
和percentFemale
。我需要将这两个属性的提交结果放在同一个子/键中。我们说密钥是L2Jq0Tg4JOS66F786pT
。
male: number = 0;
female: number = 0;
percentMale;
percentFemale;
insertdata(data: App) {
if (data.data1 == 'Male') {
this.male++;
} else if (data.data1 == 'Female') {
this.female++;
}
this.percentMale = this.male / (this.male + this.female) * 100;
console.log('percentMale', this.percentMale + '%');
this.percentFemale = this.female / (this.male + this.female) * 100;
console.log('percentFemale', this.percentFemale + '%');
this.dataList.push({
data1: data.data1,
data2: data.data2,
data3: data.data3,
time: new Date().getTime(),
});
this.dataList.push({
percentMale: this.percentMale,
percentFemale: this.percentFemale,
});
//if a key already exist
//this.dataList.update(data.$key, {
//percentMale: this.percentMale,
//percentFemale: this.percentFemale,
//});
}
我所做的功能导致更多percentMale
和percentFemale
分开存储,表格显示不必要的行。
有人能帮我解决这个问题吗?如果需要更多的片段,请告诉我。
答案 0 :(得分:0)
我想我找到了答案。
this.pertanyaanList.update("databaseKey", {
percentMale: this.percentMale,
percentFemale: this.percentFemale,
});