angularjs - Angular sort result of function -
i must order results result of function.
<div ng-repeat="x in datateam | orderby : '{{getresults(x.id)}}'"> <p>{{getresults(x.id) | number: 2}} % - {{x.team_name}}</p> </div>
getresults function calculate results, sort that.
thanks help
//****
edited
$http.get("http://localhost:8080/api/team") .then(function successcallback(response){ $scope.datateam = response.data.team; }; // datateam { "team": [ { "id": 1, "team_name": "abc" }, { "id": 2, "team_name": "fgh" }, { "id": 3, "team_name": "mno" } ] } $scope.getresults = function (item){ /* function here */ return results; }; //from json calculate getresults team_id { "teamstatistic": [ { "team_id": 1, "width": "213", "height": "423" }, { "team_id": 2, "width": "643", "height": "432" }, { "team_id": 3, "width": "526", "height": "246" } ] }
i think mean like:
<div ng-repeat="x in datateam | orderby:results"> <p>{{getresults(x.id) | number: 2}} % - {{x.team_name}}</p>
where results
method receives x
$scope.results = function(x){ return x.id; // or other math } $scope.getresults = function(id){ return id; // or other math }
full code:
function myctrl($scope) { $scope.datateam = [{ "id": 1, "team_name": "abc" }, { "id": 2, "team_name": "fgh" }, { "id": 3, "team_name": "mno" }]; var team_id = { "teamstatistic": [{ "team_id": 1, "width": "213", "height": "423" }, { "team_id": 2, "width": "643", "height": "432" }, { "team_id": 3, "width": "526", "height": "246" }] }; $scope.results = function(x) { var height = 0; angular.foreach(team_id.teamstatistic, function(item) { if (item.team_id === x.id) { height = item.height; } }); return height; } $scope.getresults = function(id) { return id; } }
output:
3.00 % - mno 1.00 % - abc 2.00 % - fgh
Comments
Post a Comment