簡體   English   中英

使用For循環,If語句和ng-repeat顯示數組項目(json)

[英]Display array items(json) using For Loop, If Statement and ng-repeat

我試圖通過兩個JSON數組對象進行篩選,以顯示從數組中選擇的結果。 我正在使用兩個For循環和一個If語句來過濾掉需要顯示的內容。

但是,我的問題在於,If語句似乎無法過濾出For循環的結果。 顯示JSON對象中的每個項目。 請幫忙。

角度/ 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>

我認為您是否缺少==符號,如果($ scope.category_limit =='珠寶首飾'){.....}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM