0

I am trying to filter through two JSON array objects in order to display selected results from the arrays. I am using two For Loops and an If Statement to filter out what needs to be shown.

However my issue comes in that the If Statement does not seem to filter out the results of the For Loop. Every item in the JSON object is displayed. Please help.

angular/javascript

      var url = generateQuery('GET', '/products', CONFIG, params);
      $scope.result = "";
      var i;
      var j;
      $scope.items = [];
      $http.get(url)
          .success(function(data, status, headers, config) {
              $scope.result = data;

              for (i = 0; i < $scope.result.products.length; i++) {

                  for (j = 0; j < $scope.result.products[i].categories.length; j++) {
                      $scope.category_limit = $scope.result.products[i].categories[j];

                      if ($scope.category_limit = 'Jewellery') {

                          $scope.items.push({
                              image: $scope.result.products[i].featured_src,
                              name: $scope.result.products[i].title,
                              price: '$' + $scope.result.products[i].price + ' (R' + ($scope.result.products[i].price * $scope.convert.results.rate.Rate).toFixed(2) + ')',
                              id: $scope.result.products[i].id,
                              cat: $scope.category_limit
                          });
                          $ionicLoading.hide();

                      } else {
                          $ionicLoading.hide();
                      }
                  }

              }

          })

html

        <div class="category-col" ng-repeat="i in items" id="swap_row_col">

            <a ng-href="#/app/products/{{i.id}}" href="#/app/products/{{i.id}}" class="no-underline">
                <img src= {{i.image}} class="category-image-col">      
                <!--<img src='images/add_to_cart.png' style="height: 24px; width: 28px; z-index: 5; position: fixed; margin-left: 34%; margin-top: -13%;">                                         -->
                <div class="category-name-col"> {{i.name}} </div>
                <div class="category-price-col"> {{i.price}} </div>
                <div class="category-price-col"> {{i.cat}} </div>
            </a>

        </div>
2
  • 1
    Can you give some details on what the returned data looks like? Commented Nov 22, 2016 at 19:29
  • Could it be that "Jewellery" is supposed to be "Jewelry"? Without seeing your data, we are just guessing here. Commented Nov 22, 2016 at 19:33

1 Answer 1

2

i think your missing the == sign if ($scope.category_limit == 'Jewellery'){ ..... }

Sign up to request clarification or add additional context in comments.

1 Comment

Okay it seems that the data objects I was receiving was the issue. Each Products object did not have the same amount of category items. $scope.category_limit == 'Jewellery' is correct though, thanks. I will mark this as the correct answer as it will solve related issues

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.