我必须按照我的功能结果订购结果。
<div ng-repeat="x in dataTeam | orderBy : '{{getResults(x.id)}}'">
<p>{{getResults(x.id) | number: 2}} % - {{x.team_name}}</p>
</div>
getResults是一些计算某些结果的函数,我想对它进行排序。
感谢您的帮助
// ****
EDITED
$http.get("http://localhost:8080/api/team")
.then(function successCallback(response){
$scope.dataTeam = response.data.team; };
// this is dataTeam
{ "team": [
{ "id": 1, "team_name": "ABC" },
{ "id": 2, "team_name": "FGH" },
{ "id": 3, "team_name": "MNO" } ] }
$scope.getResults = function (item){
/* some function here */
return results;
};
//from this JSON a calculate getResults by
team_id {
"teamStatistic": [
{ "team_id": 1, "width": "213", "height": "423" },
{ "team_id": 2, "width": "643", "height": "432" },
{ "team_id": 3, "width": "526", "height": "246" }
] }
答案 0 :(得分:0)
我认为你的意思是:
<div ng-repeat="x in dataTeam | orderBy:results">
<p>{{getResults(x.id) | number: 2}} % - {{x.team_name}}</p>
其中results
是接收x
$scope.results = function(x){
return x.id; // or other math
}
$scope.getResults = function(id){
return id; // or other math
}
完整代码:
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;
}
}
输出:
3.00 % - MNO
1.00 % - ABC
2.00 % - FGH