Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.controller('TestController', function ($scope, $http, $timeout) {
  2.     $scope.ob = [
  3.         {id: 1, prices: [{count: 2, price: 18}, {count: 3, price: 38}]},
  4.         {id: 2, prices: [{count: 2, price: 18}, {count: 3, price: 38}]},
  5.         {id: 3, prices: [{count: 2, price: 18}, {count: 3, price: 38}]},
  6.         {id: 4, prices: [{count: 2, price: 18}]},
  7.         {id: 5, prices: [{count: 3, price: 18}, {count: 5, price: 38}]},
  8.         {id: 6, prices: [{count: 1, price: 18}, {count: 2, price: 38}]},
  9.         {id: 7, prices: [{count: 4, price: 18}, {count: 1, price: 38}]},
  10.         {id: 8, prices: [{count: 2, price: 18}, {count: 3, price: 38}]}
  11.     ];
  12.  
  13.     $scope.getByCount = function (count) {
  14.         for (var i in $scope.ob) {
  15.             for (var r in($scope.ob[i].prices)) {
  16.                 if (count.indexOf($scope.ob[i].prices[r].count) === -1) {
  17.                     delete $scope.ob[i].prices[r];
  18.                 }
  19.             }
  20.         }
  21.         $timeout(function () {
  22.             console.log($scope.ob);
  23.         }, 500);
  24.     }
  25.  
  26.     $scope.getByCount([1, 2]);
  27.  
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement