Searching for objects with distinct hash codes using an AngularJS filter

My title may be long, but I want to explain something:

I am using a service called:

divisionService

This service has a function that returns a list of all Divisions in my system.

I use this list to populate a select:

   <select class="form-control input-sm" ng-model="search.division.name"
                            ng-options="item as item.name for item in auoCtrl.divisionList">
                        <option value="">Alle</option>
   </select>

Then I make an HTTP request that selects my users (along with some extra statistics)

    $http.get(api.getUrl('getUserStats', null))
    .success(function (response) {
        auoc.users = response;
    });

The response might contain objects like this:

[Object, Object, Object, Object, Object]

Each object looks like this:

object = {
avg_score : 5
completed_modules:
user: object{
          division: object{id: 19, location_id: 5, name: "Udvikling", organization_id: 1
            },
division_id: 19
id: 1
image_path: "img/profileIcon.png"
     }
}

There is a lot of data inside each user object.

Now, I want to bind my select to sort my list of users by their division object. I tried using ng-model="search.division" and then in my repeat loop:

 ng-repeat="user in auoCtrl.users | filter: search"

Unfortunately, when I change the value of the select, everything disappears.

So, my question is, how do I search for the division in this example?

Answer №1

After examining the code provided and carefully considering the question at hand, I have developed a straightforward code snippet which effectively filters based on the division name.

The challenge arises from the layered structure of the user and their respective divisions. This necessitates a step-by-step approach to filter data based on the desired criteria.

In this scenario, I have successfully filtered users by the selected department name.

<ul>
  <li ng-repeat="user in auoCtrl.users | 
            filter: {user: {division:{name:auoCtrl.selectedDivision.name}}}">
    {{user.user.division.name}}
    <br />{{user | json}}</li>
</ul>

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

Is there a way to include multiple web parts that utilize an angularjs module?

How do I incorporate multiple web parts in SharePoint using AngularJS modules? I have a web part where I've utilized AngularJS. The issue arises when attempting to add this web part multiple times on a page - separating the Angular module names poses ...

Exploring the Synergy Between Play 2.3.x, Webjars, and Requirejs: Unveiling

Queries: Is there a way to streamline the process of setting paths and shims in requirejs for webjars and their dependencies without manual intervention? (Especially for webjars that include a requirejs.config() call?) Does anyone have a straightforward e ...

Is there a way to verify if a Backbone.View is actively displayed in the DOM?

Is there a way to determine if a Backbone.View is currently rendered in the DOM, so that I do not need to rerender it? Any suggestions on how this can be achieved? Thanks and regards ...

Obtain values from a specific set, and then filter out values from an array that correspond to the index of that set into distinct arrays

The Problem I'm Facing Currently, I am dealing with a large data table that contains a mix of relevant and irrelevant data. My goal is to filter out the information I care about and display it in a more concise table. Using RegEx, I have managed to i ...

Updating website content dynamically using AJAX and URL manipulation without refreshing the page (Node.js)

How can I update the inventory without refreshing the page using both button events and URLs? I want to be able to update to a specific page based on the URL parameter (like /inventory/2) when it is passed to the route. Currently, my AJAX request works but ...

What is the best way to set the state to false upon unmounting a component in react?

Currently, I am controlling the state of a dialog using context. Initially, the isOpen state is set to false. When the add button is clicked, the state isOpen becomes true and clicking the cancel button will revert it back to false. If the user does not c ...

Break up the JavaScript code into modules to avoid duplicating blocks of code detected by

There is a block of code that SONAR has identified as duplicate. I am looking for guidance on how to address this issue. import fields from '../../utils/utils'; dispatch( fields.change([ { id: 'userData', value: ...

Is the array empty once the functions have been executed?

app.post('/api/edit-profile', regularFunctions, async function (req, res) { let email = req.body.email let password_current = req.body.password_current connection.query('SELECT * FROM accounts WHERE id = ?', req.body.id, asy ...

Wrap a URL with link tags directive

I am struggling with formatting a text that contains new line separators and URLs: first row\nFind me at http://www.example.com and also\n at http://stackoverflow.com. I need to create a directive that can take a string as input and wrap any UR ...

Utilizing Jquery for ASP.NET, an AJAX call dynamically populates a list

My user interface is designed to populate a select dropdown menu using data retrieved from a database through an AJAX call. The C# web method responsible for this operation is structured as follows: private static List<List<string>> componentT ...

Tips for locating a particular row in Protractor

Can you explain how the solution discussed in this Stack Overflow thread works? I'm interested in understanding the specific logic behind selecting ID0001 in the code snippet provided below: element.all(by.repeater('item in $data track by $index ...

Enhancing Browser Experience: The correct method for dynamically adding an AngularJS controller through a Chrome Extension's Content

Currently, I am in the process of developing a Chrome extension using AngularJS. To attach a controller to the required DOM elements on a webpage, I have been utilizing the following content script code: setController() { if(this.setContollerConditio ...

URL validation RegEx in AngularJs using Javascript

I am looking for the following URLs to return as true other.some.url some.url some.url/page/1 The following URL should be flagged as false somerandomvalue Here is the regex I have been experimenting with so far: /^(?:http(s)?:\/\/) ...

Modify the row's background color after clicking the delete button with jquery

Greetings, I am facing an issue with changing the color of a row in a table when clicking on a delete button. Despite trying various methods, I have not been successful. How can I modify the ConfirmBox() method to change the row's color? Your assistan ...

Dynamic Radio Buttons in AngularJS with Required or Optional Selections

I have developed a content management system that allows users to add various types of form fields, including radio buttons. Users can specify whether a radio button is required or not. If it is required, the user must select a radio button, otherwise a m ...

Tips for transferring value between custom elements in Polymer 1.0

I have developed two unique custom elements named student-details.html and student-service.html This is how the student-details.html file is structured: <link rel="import" href="../bower_components/polymer/polymer.html"> <link rel="import" hre ...

Access to the Heroku app is restricted to the specific device that I have designated for its

I am having some issues with deploying my app and need some help. Here are the details: Using the free plan on Heroku On other devices, only the background image/color/pattern is visible Errors on other devices (mainly related to Redux): On Firefox ...

What is the best way to filter two tables using only one search bar?

In my Vue2 application, I have implemented a pair of data tables on one of the pages. Each table is placed behind a tab, allowing users to choose which one they want to view. The search bar, however, is not confined within a tab as I wanted to avoid duplic ...

typescript - instantiate an object using values stored in an array

Assume we have a model defined as follows. export interface Basicdata { materialnumber: number; type: string; materialclass: string; } We also have an array containing values that correspond directly to the Basicdata model in order, like this: ...

Accessing specific documents in Firebase cloud functions using a wildcard notation

Currently, I am working on implementing Firebase cloud functions and here are the tasks I need to achieve: Monitoring changes in documents within the 'public_posts' collection. Determining if a change involves switching the value of the &ap ...