【发布时间】:2015-12-31 00:18:46
【问题描述】:
有没有办法将日期选择器值添加到 Firebase 数据库中?
类似的东西?
$scope.AddPost = function() {
...
Published: $scope.post.Published.DATESTAMP
...
}
来自materialize datepicker 值,如下所示:
<input type="date" ng-model="post.Published" class="datepicker">
来自选择器的服务器端代码:
<input type="text" ng-model="post.Published" class="datepicker ng-pristine ng-valid picker__input ng-touched picker__input--active picker__input--target" readonly="" id="P2078770150" tabindex="-1" aria-haspopup="true" aria-expanded="true" aria-readonly="false" aria-owns="P2078770150_root">
尝试过:
$scope.AddPost = function() {
myPosts.$add({
Title: $scope.post.Title,
Intro: $scope.post.Intro,
Body: $scope.post.Body,
Published: $scope.post.Published,
Author:$scope.post.Author
})
加载除日期之外的所有内容。
我一直在寻找一个等价物,但只找到了 Firebase.ServerValue.TIMESTAMP,这不是我想要的,因为我需要人们能够手动选择日期。
【问题讨论】:
-
这个问题有两个方面:从用户那里获取日期与在 Firebase 中存储数据。这两个是不同的主题,有很多方法可以混合它们。在 Firebase 中存储日期通常通过以下两种方式中的一种(或两种)完成:将其存储为时间戳与将其存储为字符串。你应该做哪一个,取决于你,什么最适合你的用例。
-
如果您在从日期选择器中获取值时遇到问题,您必须展示您已经尝试过的内容。
-
我在上面编辑了我的问题。我试图按原样输入它,但没有加载。有没有办法告诉 Firebase 它应该是哪种格式?