Angularjs: How to split half of any array list
我目前把json中的一个列表分成前10个,第二个是11到20个。但是,对于列表的任何长度,我都希望将其拆分为一半。我该怎么做?
这是我的密码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | function loadTop() { $webServicesFactory.get($marketProvider[$scope.currentMarket].topGetURL, {AnonymousToken: $marketProvider[$scope.currentMarket].token}).then( function success(response) { $scope.top = response.Stock.slice(0, 10); $scope.low = response.Stock.slice(10, 20); console.log($scope.top); loadStockCount(); loadTop(); loadLow(); $ionicLoading.hide(); }, function error(error) { $ionicLoading.hide(); } ); } |
1 2 3 4 | var numStocks = response.Stock.length; var halfStocks = Math.round(numStocks / 2); $scope.top = response.Stock.slice(0, halfStocks); $scope.low = response.Stock.slice(halfStocks, numStocks); |