0

日付ピッカーの値を Firebase データベースに追加する方法はありますか?

これらの線に沿った何か?

  $scope.AddPost = function() {
          ...
          Published: $scope.post.Published.DATESTAMP
          ...
        }

次のようなマテリアライズ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人々が手動で日付を選択できるようにする必要があるため、私が望むものではないものしか見つかりませんでした.

4

2 に答える 2

1

さまざまなスレッドをたどることで、これを修正することができました。だから私は

HTML

 <div class="form-group">
                        <label class="col-md-4 control-label" for="numDate">Choose a Date</label>
                        <input type="date" name="Published" ng-model="post.Published" class="datepicker" required>
                        <span class="error" ng-show="input.Published.$error.required">
                    </div>

AddPost() 関数内:

Published: new Date($scope.post.Published).getTime(),

角度のある

<p>By: {{post.Author}} &nbsp; Published on: {{post.Published |    date:'mediumDate'}}</p>

そのため、追加プロセスで変換しようとする代わりに、タイムスタンプを保持してビューで変換しました。

ありがとう

于 2015-10-03T12:36:15.770 に答える
1

@Frankが言ったように、日付は、要件に応じて、文字列またはタイムスタンプとしてfirebaseに保存できます。

試す

$scope.AddPost = function() {
      ...
      Published: new Date($scope.post.Published).getTime();
      ...
    }
于 2015-10-02T18:55:45.317 に答える