【问题标题】:How to get the post date upon submit?如何在提交时获得发布日期?
【发布时间】:2016-12-19 17:12:00
【问题描述】:

如何自动将日期作为属性推送到 Firebase?下面是使用 alertcontrol 方法添加书籍的功能。

addBook() {
console.log("add book button click-ed");

let alert = this.alertCtrl.create({
  title: 'Book Title and Author',
  message: 'Book Cover',
  inputs: [
    {
      name: 'title',
      placeholder: 'Book Title'
    },
    {
      name: 'author',
      placeholder: 'Author of the Book'
    },
    {
      name: 'cover',
      placeholder: 'Cover URL'
    },
  ],
  buttons: [
    {
      text: 'Cancel',
      handler: data => {
        console.log('Cancel click-ed')
      }
    },
    {
      text: 'Save Book',
      handler: data => {
        this.books.push({
          title: data.title,
          author: data.author,
          cover: data.cover,
        })
      }
    }
  ]
})
alert.present();

}

我已经为标题、作者和封面设置了道具输入。它工作正常。 addBook() 函数绑定到具有该方法的按钮。但是,如果我想在用户单击按钮时获取发布日期并将其作为道具“日期”添加到 Firebase,我应该怎么做?

【问题讨论】:

    标签: javascript angular firebase firebase-realtime-database ionic2


    【解决方案1】:

    你可以使用firebase.database.ServerValue.TIMESTAMPhttps://firebase.google.com/docs/database/web/offline-capabilities#server-timestamps

    【讨论】:

      猜你喜欢
      • 2017-01-12
      • 2014-04-02
      • 2015-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      相关资源
      最近更新 更多