【发布时间】:2017-03-08 02:40:59
【问题描述】:
我制作了一个反应组件,它记录每次我的猫被喂食的情况。但是,目前它不会每天自动创建一个新的空日志。我正在尝试添加一种方法来在每天午夜创建一个新条目,但为了使其与我制作的现有组件一起使用,每个新条目都需要以“DD-MM-YYYY”格式命名.虽然我可以重新设计组件以不使用它,但当我进入 firebase 以查看日志的创建日期并且不想更改它时,它一目了然。
所以这是我的问题:每当我尝试执行以下操作时,firebase 都会忽略我的日期格式并输入一个随机键:
this.midnightCheck = () => {
// If it is midnight, update the state
if(moment().format('HH:mm') === '00:00') {
this.dbroot.push(moment().format('DD-MM-YYYY')).child('date').set(moment().format('DD-MM-YYYY'))
}
}
我也尝试过 this.dbroot.set() 但这不起作用,因为它需要先存在 childref。
更新:我刚刚尝试了以下在技术上有效的方法,但它也覆盖了整个 ref,而不是仅仅向 ref 添加新日期。
this.midnightCheck = () => {
// If it is midnight, update the state
if(moment().format('HH:mm') === '18:34') {
console.info('midnightCheck is updating the state')
this.dbroot.child(moment().format('DD-MM-YYYY')).set({
date : moment().format('DD-MM-YYYY'),
logs : {}
})
}
}
有什么建议吗?
【问题讨论】:
标签: javascript firebase firebase-realtime-database