javascript - Angular $http result sort and bind to view? -
i'm trying render results data pulled successful $http.get, push through 2 or 3 functions sort/concat/filter data few different ways, , store rest of apps duration.
i have following service:
myapp.service('versionservice', function($http, $log, $q) { var self = this; this.issues = { all: [] }; this.versions = { all: [], byname: [], byid: [] }; var query = {}; query.jql = "fixversion in unreleasedversions() order fixversion asc"; $http({ url: '/search/versions', method: 'post', //cache: true, data: query }) .then(function (response) { //console.log(response.data.issues); for(var = 0; < response.data.issues.length; i++) { self.issues.all.push(response.data.issues[i]); for(var j = 0; j < response.data.issues[i].fields.fixversions.length; j++) { self.versions.all.push(response.data.issues[i].fields.fixversions[j]); } } }, function (err) { console.log(err); }); });
my controller:
myapp.controller('filteredcontroller', function($scope, $http, $log, versionservice) { $scope.isactive = function(version) { return version == versionservice.selectedv; }; $scope.issues = { all: versionservice.issues.all }; $scope.versions = { all: versionservice.versions.all, byname: versionservice.versions.byname, byid: versionservice.versions.byid }; });
no matter how try it, if put sort/filter/concat on this.versions.byname in controller, gives blank array return. i'm guessing because sort/filter/concat running before http.get , loops finish? means view doesn't show if try pull vesions.byname/id/
how run functions sort/filter/concat data, put in other arrays in versions object, have binded view?
i trying use following function:
var versionsbyname = function() { var prev = null; self.versions.byname = self.versions.all .concat() .sort() .filter(function (i) { if (i.name !== prev.name) { prev = i; return true; } }) };
no matter put it, or if make iife, won't work.
Comments
Post a Comment