2017-04-27 3 views
0

私はcloudant dbに接続し、ドキュメントを取得しようとしています。特定のフィールドの配列(querytimeなど)があります。複数のドキュメントがあり、各ドキュメントにはクエリ時間フィールドに複数のエントリがあるため、その配列から最新のクエリ時間を取得する必要があります。クラウド内のJSON文書に保存されたデータの配列から最新のデータを取得するにはどうすればよいですか?

querytime

["Tue Apr 25 07:32:50 2017", "Tue Apr 25 07:33:51 2017", "Tue Apr 25 07:34:51 2017", 30 more...] 

$http(req).then(function(result){ 
    $scope.tableData = result.data.rows; 
    $scope.max = Math.max.apply(Math,$scope.tableData.map(function(doc){return doc.querytime;})); 
    }, 
    function(){ 
    console.log("Failed at grabbing data"); 
       }); 

<body ng-app="myApp" ng-controller="tutorialCtrl"> 
<p> 
{{"Hello " + "you"}} 
</p> 
    <div ng-repeat="doc in tableData"> 
     {{doc.doc.querytime}} 
    </div> 
</body> 

答えて

0

私はquerytimeが数値だった場合、あなたのコードが動作すると思います。

return doc.querytime; 

をして:

return Math.max.apply(Math,doc.querytime) 

私は置き換え

$scope.max = Math.max.apply(Math,$scope.tableData.map(function(doc){ 
    return Math.max.apply(Math,doc.querytime); 
})); 

注:querytimeはそうのように、あなたは、アレイ内の各最大の最大を取得する必要があります配列であるので、すべての文書で最大の価値を提供します。あなたは、各文書の最大にしたい場合は、このような何かをするだろう:

コントローラー:

$scope.getMaxQuerytime() = function(doc) { 
    return Math.max.apply(Math,doc.querytime); 
} 

HTML:

<div ng-repeat="doc in tableData"> 
    {{getMaxQuerytime(doc)}} 
</div> 
関連する問題