2016-03-28 6 views
1

jsonデータからの日付をApr 15、2015 10:15 PMとしています htmlページの10:15 PMのようなjsonの応答データからの時刻のみを表示します ここに私は私のjsの機能とhtmlコード{{x.date |日付: 'hh:mm'}}は機能していません

JS関数を入れ

function smsHistory($scope) { 
    var user_id = sessionStorage.getItem('user_id'); 
    var authentication_key = sessionStorage.getItem('auth_id'); 
    $scope.loading = true; 

    $.ajax({ 
     type: 'GET', 
     // here I define a url to get api data 
     url: '............/get_sms_history', 
     data: {user_id: user_id, authentication_key: authentication_key}, 
     timeout: 5000, 
     success: function (response) { 
      $scope.loading = false; 
      // here i parse the data in json    
      $scope.records = JSON.parse(response).records; 
      $scope.$apply(); 
      var x = $scope.records; 

      $scope.setbank = function (x) { 
      }; 

      $scope.isSelected = function (x) { 
       return $scope.selected === x; 
      }; 
     }, 
     error: function (response) { 
      $scope.error = true; 
      $scope.$apply(); 
     } 
    }); 
} 

HTMLコード

<div ng-controller="smsHistory"> 
    <div ng-show="loading" class="loading"><img src="img/loading.gif" height="50px" width="50px"></div> 
    <ons-list class="plan-list"> 
     // here i use ng-repeat to repeat the data if multiple records are their 
     <ons-list-item modifier="chevron" class="plan" ng-repeat="x in records"> 
      <ons-row> 
       <ons-col width="80px" class="plan-left"> 
        // here i got the date value from json data 
        <div class="plan-date">{{x.date}}</div> 
        <div class="plan-duration"></div> 
       </ons-col> 
       <ons-col width="6px" class="plan-center" ng-style="{backgroundColor:a % 3 == 1 ? '#3399ff' : '#ccc'}"> 
       </ons-col> 
       <ons-col class="plan-right"> 
        <div class="plan-name">{{x.name}}</div> 
        <div class="plan-info"> 
         <div> 
          <ons-icon icon="ion-android-textsms"></ons-icon> 
          &nbsp;{{x.phone}} 
         </div> 
         <div> 
          <span>{{x.charge}}</span>&nbsp;&nbsp;<span>{{x.balance}}</span>&nbsp;&nbsp;<span>{{x.status}}</span> 
         </div> 
         <div> 
          <ons-icon icon="fa-map-marker"></ons-icon> 
          &nbsp;{{x.destination}}<span></span> 
         </div> 
        </div> 
       </ons-col> 
      </ons-row> 
     </ons-list-item> 
     <ons-list-item></ons-list-item> 
    </ons-list> 
</div> 

AngularJSを使用して、このdatetime jsonデータからのみ時間が必要です。私を助けてください。 ありがとうございます。

答えて

1

次のあなたのライン

$scope.records = JSON.parse(response).records 

を交換してください:

var records = $scope.records = JSON.parse(response).records; 
angular.forEach($scope.records, function(record) { 
    record.date = new Date(record.date); 
}); 
$scope.records = records; 

私たちは、日付オブジェクトに文字列の日付を変換し、基本的にあります。

+0

ありがとうshashank! –

+0

私は、その日付オブジェクトからの時間だけを欲しがっています。 –

+0

今、 '{{x.date | date: 'hh:mm'}} 'をHTMLに追加します。 –

関連する問題