Concealing an item in an Angular Ionic repeater

I am creating a customizable list control where users can filter through different data levels. This list control consists of 4 hierarchical levels with numerous items. Initially, only the first level item is displayed. Upon clicking on the first level, the second level appears while hiding the first one. Subsequently, the user can click on the second level to reveal the third level and hide the second level, and so on.

When selecting a specific first-level item, all other first-level items should be hidden. Currently, when choosing a first-level item, the second level becomes visible for all first-level items. Ideally, upon selecting a first-level item, all other first-level options should disappear to streamline the filtering process within the selected category. For example, if "Men" is selected, then the "Womens" section should be automatically hidden.

The hierarchical structure is as follows:

Department -> Product Type -> Style -> Color Size Combination

The JSON data is already organized following this hierarchy:

[
   {
      "departmentName":"Womens",
      "productTypes":[
         {
            "name":"Standard",
            "styles":[
               {
                  "name":"2001",
                  "details":[
                     {
                        "color":"blue",
                        "size":"m",
                        "productNum":1234567891212
                     },
                     {
                        "color":"blue",
                        "size":"x",
                        "productNum":1234567891212
                     },
                     {
                        "color":"blue",
                        "size":"xxl",
                        "productNum":1234567891212
                     },
                     {
                        "color":"blue",
                        "size":"s",
                        "productNum":1234567891212
                     }
                  ]
               }
            ]
         }
      ]
   },
   {
      "departmentName":"Men",
      "productTypes":[
         {
            "name":"Standard",
            "styles":[
               {
                  "name":"2001Men",
                  "details":[
                     {
                        "color":"green",
                        "size":"m",
                        "productNum":1234567891212
                     },
                     {
                        "color":"green",
                        "size":"x",
                        "productNum":1234567891212
                     },
                     {
                        "color":"green",
                        "size":"xxl",
                        "productNum":1234567891212
                     },
                     {
                        "color":"green",
                        "size":"s",
                        "productNum":1234567891212
                     }
                  ]
               }
            ]
         }
      ]
   }
]

Below is the corresponding HTML code:

<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title></title>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" type="text/css" href="http://code.ionicframework.com/1.0.0-beta.11/css/ionic.min.css">
  <script src="http://code.ionicframework.com/1.0.0-beta.11/js/ionic.bundle.min.js"></script>
  <script src="script.js"></script>
</head>
<body ng-app='todo'>
  <ion-pane>

    <ion-content>
      <div class="container padding" style="background-color: #fff;" ng-controller="MyCtrl">
        <div class="row">
          <div class="col col-100">
            <span ng-repeat="f in filter">
              {{f}}&nbsp;<i class="icon ion-ios-close-empty"></i>
              &nbsp;<i class="icon ion-ios-arrow-thin-right" ng-show="$index < (filter.length-1)"></i>
            </span>
          </div>
        </div>
        <div class="list" ng-repeat="item in filterData">
          <div class="item item-divider" ng-click="setFilter(item.departmentName, 1);" ng-show="showDepartments">
            {{item.departmentName}}
          </div>
          <div ng-repeat="pt in item.productTypes">
            <div class="item item-divider" ng-click="setFilter(pt.name, 2);" ng-show="showProductTypes">
              {{pt.name}}
            </div>
            <div ng-repeat="style in pt.styles">
              <div class="item item-divider" ng-click="setFilter(style.name, 3);" ng-show="showStyles">
                {{style.name}}
              </div>
              <div ng-repeat="styleLine in style.details">
                <div class="item item-divider" ng-click="setFilter(styleLine, 4);" ng-show="showStyleDetails">
                  {{styleLine.color}} - {{styleLine.size}}
                  <br/> {{styleLine.productNum}}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </ion-content>
  </ion-pane>
</body>

</html>

Here is the JavaScript code:

angular.module('todo', ['ionic'])

.controller('MyCtrl', function($scope) {
  $scope.filter = [];
  $scope.showDepartments = true;
  $scope.showProductTypes = false;
  $scope.showStyles = false;
  $scope.showStyleDetails = false;

  $scope.setFilter = function(filterValue, level) {
    if (level != 4) {
      $scope.filter[$scope.filter.length] = filterValue;
    } else {
      $scope.filter[$scope.filter.length] = filterValue.color;
      $scope.filter[$scope.filter.length] = filterValue.size;
    }
    if (level == 1) {
      $scope.showDepartments = false;
      $scope.showProductTypes = true;
    }
    if (level == 2) {
      $scope.showProductTypes = false;
      $scope.showStyles = true;
    }
    if (level == 3) {
      $scope.showStyles = false;
      $scope.showStyleDetails = true;
    }
    if (level == 4) {
      $scope.showStyleDetails = false;
    }
  }

  $scope.title = 'Ionic';
  $scope.filterData = [{
    "departmentName": "Womens",
    "productTypes": [{
      "name": "Standard",
      "styles": [{
        "name": "2001",
        "details": [{
          "color": "blue",
          "size": "m",
          "productNum": 1234567891212
        }, {
          "color": "blue",
          "size": "x",
          "productNum": 1234567891212
        }, {
          "color": "blue",
          "size": "xxl",
          "productNum": 1234567891212
        }, {
          "color": "blue",
          "size": "s",
          "productNum": 1234567891212
        }]
      }]
    }]
  }, {
    "departmentName": "Men",
    "productTypes": [{
      "name": "Standard",
      "styles": [{
        "name": "2001Men",
        "details": [{
          "color": "green",
          "size": "m",
          "productNum": 1234567891212
        }, {
          "color": "green",
          "size": "x",
          "productNum": 1234567891212
        }, {
          "color": "green",
          "size": "xxl",
          "productNum": 1234567891212
        }, {
          "color": "green",
          "size": "s",
          "productNum": 1234567891212
        }]
      }]
    }]
  }];
})

Access the Plunkr demo by clicking on the following link:

http://plnkr.co/6YdnId

Answer №1

Success! I managed to make it function properly by implementing a property directly on the item to conceal the top level for all items except the one selected. Check out the updated plunkr. Hopefully, this solution will benefit others.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Update the Vue component upon fetching new data

How can I continuously refresh the list of items when a button in a sibling component is clicked? The watch method only triggers once, but I need it to constantly refresh. This is the parent element: <template> <div class="container"& ...

What is the best way to handle JSONp response parsing using JavaScript?

I'm relatively new to working with Javascript and I am currently attempting to retrieve data from an External API located on a different website. My goal is to extract the information, parse it, and then display specific parts of it within my HTML pag ...

Retrieval of components from JSON array of objects

I have a JSON array containing objects stored on the server. How can I access the first object to print its contents? The data is in the following format: [ { "eventId": "8577", "datasetId": "34", "nodeId": "8076", "typeId": "4", "type": ...

Tips for customizing the IconButton appearance in material-ui

While Material-ui offers a default icon button, I am interested in customizing its design to resemble this: IconButton design needed Could you please advise me on how to make this change? Thank you. ...

Problem with Google's PageSpeed Insights - Focus on Making Most Important Content Visible

During the process of creating a comprehensive website for a client who has a strong affinity towards Google tools and recommendations, I have encountered an interesting challenge: Despite my best efforts, I seem unable to attain a flawless score for the ...

CKEditor seems to have overlooked the importance of proper paragraph formatting

Incorporating CKEditor into my front-end project using Laravel has been a great help. However, I am facing an issue where I want to eliminate automatic paragraphs but still allow users to create them by clicking the paragraph button. Is there a way to ac ...

The 'authorization' property is not available on the 'Request' object

Here is a code snippet to consider: setContext(async (req, { headers }) => { const token = await getToken(config.resources.gatewayApi.scopes) const completeHeader = { headers: { ...headers, authorization: token ...

Bar graph constructed using a pair of div elements

I extracted two values from an array: $target = $data->data[2][32][3]; For this particular example, $target = 9.83%. $clicks = $data->data[1][32][3]; And in this case, $clicks = 7.15%. I have created a bar-like chart using three main div elements ...

Transform my Curl script into a NodeJS app

I'm trying to replicate the functionality of a curl command within my NodeJS application, but I am facing some difficulties. Any guidance on how to achieve this would be greatly appreciated. curl -H "Authorization: bearer $TOKEN" If I already hav ...

What is the best method to collect information from multiple AJAX requests?

In addition to synchronous AJAX calls, what is the most effective approach for handling a situation like this? var A = getDataFromServerWithAJAXCall(whatever); var B = getDataFromServerWithAJAXCallThatDependsOnPreviousData(A); var C = getMoreDataFromServe ...

Tips for displaying the overlay in a jQuery UI modal dialog

The demonstration shows that the overlay is displayed correctly and all elements below it are disabled: <div class="ui-widget-overlay" style="width: 1920px; height: 650px; z-index: 1001;"></div> However, on my webpage, I am still able to inte ...

Determine whether a child node is an element or a text node using JavaScript

I am experiencing an issue with the childNodes property. Here is the scenario: <ol> <li>Coffee</li> <li>Tea</li> <li>Coca Cola</li> </ol> //childNodes.length = 7 However, <ol><li> ...

Exploring the Safari browser with Polymer 2.0

Looking for some help with a question I have... I've been experimenting with the new Polymer 2.0 preview on Safari, but it doesn't seem to be working correctly. I'm using a simple code (just my-element) in the index.htm file, loading the pol ...

Building a basic music player with the <audio> element and JavaScript / jQuery

I am new to Javascript and jQuery, and this is my first time posting a question here. I have been trying to create custom functions for the HTML5 audio tag by following tutorials online. Despite my efforts, I cannot seem to get it working. Although I can m ...

Why does appending to a TextArea field fail in one scenario but succeed in another when using Javascript?

There is a JavaScript function that captures the value from a select dropdown and appends it to the end of a textarea field (mask) whenever a new selection is made. function addToEditMask(select, mask) { var selectedValue = document.getElementById(sel ...

Tips for regularly retrieving information from a psql table

I have a scenario where I am retrieving data from a psql table and converting it into a JSON array to be used for displaying a time series chart using JavaScript. The data that is passed needs to be in the form of an array. Since the data in the table get ...

Is there a way to match a compressed javascript stack trace with a source map to pinpoint the correct error message?

When managing our production server, I have implemented minified javascript without including a map file to prevent users from easily deciphering errors. To handle angular exceptions caught by $exceptionHandler, I developed a logging service that forwards ...

Adjust the header image as you scroll

Currently, I have a static image in the header of the page. I'm looking to have the image change to a different one when half the page has been scrolled. Do I need to utilize JavaScript for this functionality or is it achievable with CSS alone? bo ...

Utilizing Ajax technology to load script in Tapestry 5

I have two components, a "DirectoryViewer" and a "MediaViewer", that I created. The Directory Viewer displays a list of file names and contains a MediaViewer component to show the selected file. This setup is functioning properly. Within the DirectoryView ...

Uniform Image Sizes in Bootstrap Carousel (With One Exception)

I am encountering a JavaScript exception related to image size. I am trying to set a fixed size for the images in my carousel, allowing them to auto adjust or resize without concern for distortion or pixelation. I have experimented with max-width and widt ...