Firebase - push()回调

exo*_*lav 1 push callback firebase

有什么方法可以找出我的数据何时使用push()方法保存在数据库中?我写了下面的代码,但它多次保存数据......

db.ref('news').push(opts).then(() => {
    // do smth. (e.g. hide preloader) when data were succesfully saved
})
Run Code Online (Sandbox Code Playgroud)

exo*_*lav 6

如果我没错,push()回调应该是这样的:

db.ref('news').push(opts, function(error) {
  if (error)
    console.log('Error has occured during saving process')
  else
    console.log("Data hss been saved succesfully")
})
Run Code Online (Sandbox Code Playgroud)