i need loop list of urls , display results in 1 table. seems orderby not work because list($scope.versions) multiple http calls , http asynchronous.
controller:
var callapi = function (app, env, index, url) { $http.get(url). success(function(data) { data.pos=index; $scope.versions[app].push([data]); }). error(function(data, status) { var errordata = {}; errordata.pos=index; $scope.versions[app].push([errordata]); }); console.log($scope.versions); }; html:
<tbody> <tr ng-repeat="(k,v) in versions"> <td>{{k}}</td> <td ng-repeat="item in v | orderby:'item[0].pos'" ng-class="{'danger': item[0].error === true, 'success': item[0].error === false}"> [{{item[0].pos}}] </td> </tr> </tbody>
it's little unclear you're trying , it's unclear data looks like, in general sense, can sort data comes in.
for example, use splice() insert data needs in array:
$scope.items = []; var urls = [ <some urls> ]; urls.foreach( function (url) { $http.get(url) .success( function (data) { var position = getposition(data); $scope.items.splice(position, 0, data); }) .error( function (data, status) { // handle error case }); }); function getposition (data) { // code find element // should inserted array return position; } or, sort data every time after add new data:
$scope.items = []; var urls = [ <some urls> ]; urls.foreach( function (url) { $http.get(url) .success( function (data) { $scope.items.push(data); $scope.items.sort(itemscomparefunc) }) .error( function (data, status) { // handle error case }); }); function itemscomparefunc (a, b) { // logic compare both items }
Comments
Post a Comment