The usage of `indexOf(model.object)` instead of `indexOf(model)` is not achieving the desired outcome

My goal is to display a list of users in a store. Everything works perfectly when using the user model specified below.

// Model
store : { type: Array },

The next step involves radio buttons for each individual store.

<!-- Button for 'all' users -->
<label class="btn-l33t" ng-model="radio.model" btn-radio="allstores">
  {{global.user.company || 'null'}}
</label>

<!-- Button that filters users by store. Everything working as expected -->
<ul>
  <li ng-repeat="store in global.user.store">
    <label class="btn-l33t" ng-model="radio.model" btn-radio="store">
     {{store}}
    </label>
  </li>
</ul>

Finally, there's the table displaying all users.

<!-- Display user if store is included in user.store -->
<!-- Everything functioning correctly -->
<tr ng-show="user.store.indexOf(radio.model) != -1 || radio.model === allstores" data-ng-repeat="user in users">

I have now updated my model to include objects within the stores array, allowing for sections within each store.

store: {
  type: Array,
  thing: {
      name: String,
      section: Array,
  }
},

While the list of users is displaying correctly, the table is no longer filtering. Clicking on a radio button does not trigger any changes. I've updated the radio buttons to display both the store name and section accurately.

<label class="btn-l33t" ng-model="radio.model" btn-radio="allstores">
  {{global.user.company || 'null'}}
</label>

<ul>
  <li ng-repeat="store in global.user.store">
    <label class="btn-l33t" ng-model="radio.model" btn-radio="store">
      {{store.name}} <!-- changed {{store}} to {{store.name}} -->
      <!-- The property is store.name instead of store.thing.name -->
    </label>
    <!-- Sections added successfully -->
    <ul>
      <li ng-repeat="section in store.section" >
        <label class="btn-l33t" ng-model="radio.model2" btn-radio="section">
          {{section}}
        </label>
      </li>
    </ul>
  </li>
</ul>

The challenge arises when trying to display the users in the table. Unsure about the necessary adjustments to make it work.

<tr ng-show="user.store.thing.name.indexOf(radio.model.name) != -1 || radio.model === null" data-ng-repeat="user in users">

Edit/Update: Here's how stores are being added:

var obj ={ 
   name: $scope.datStore.name, 
   section: ["grocery","utensils"]
}
user3[0].store.push(obj);

Perhaps this explains why stores.name is functional while stores.thing.name isn't. Shouldn't the model be updated accordingly? Surprisingly, the current model accepts this arrangement.

Answer №1

After reviewing your most recent update, it appears that the store in question is structured like this:

store: [
        {name:'name1', section:['section1', 'section2']}, 
        {name:'name2', section:['section3', 'section4']}
       ]

Based on this structure, it seems that the desired action is as follows:

<tr ng-show="!radio.model || (user.store|filter : {name : radio.model.name}).length > 0" data-ng-repeat="user in users">

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

Including item from ajax not within $.when function finished

function fetchData(){ return $.ajax({ url : 'URL1', data : { id : id }, type : 'GET', }); } function fetchItemData(item_id) { return $.ajax({ url: 'URL2', data: { item_id: it ...

Eliminate parameter from URL

Here is the URL I am working with: http://my.site/?code=74e30ef2-109c-4b75-b8d6-89bdce1aa860 My goal is to redirect to this URL: http://my.site#/homepage To achieve this, I use the following code snippet: import { push } from 'react-router-redux& ...

Having difficulty retrieving text data from a web URL using JavaScript

I am trying to extract text data from a web URL () My approach involved using two node modules. 1) Using crawler-Request it('Read Pdf Data using crawler',function(){ const crawler = require('crawler-request'); functio ...

Warning: Nodemailer has issued a deprecation warning regarding the outdated `punycode` module

Looking to automate daily email sending through a Gmail account, I have been experimenting with nodemailer and crafted this simple test code: const fs = require('fs'); const path = require('path'); const nodemailer = require('nodem ...

There was an issue when trying to process the Javascript data structure with JSON.parse

Currently, I have the following data stored in a JavaScript variable: "{'Headings': [{'name': 'Behavior', 'majorTopic': 'N', 'vote': {'down': 1, 'up': 1}}, {'na ...

Creating a compilation of material-ui using browserify

I am currently in the process of incorporating material-ui (material-ui.com) JavaScript into my project to utilize its React components. To streamline this process, I have been utilizing browserify to consolidate all the JavaScript files into a single one ...

What is the best way to dynamically disable choices in mat-select depending on the option chosen?

I was recently working on a project that involved using mat-select elements. In this project, I encountered a specific requirement where I needed to achieve the following two tasks: When the 'all' option is selected in either of the mat-select e ...

Yep, implementing conditional logic with the `when` keyword and radio buttons

I seem to be encountering an issue with my implementation (probably something trivial). I am utilizing React Hook Form along with Yup and attempting to establish a condition based on the selection of a radio group. The scenario is as follows: if the first ...

What could be causing the data variable to be undefined when executing the resource query transform

Embarking on my journey with angular, I find myself struggling to pass a complex JavaScript object as a query parameter. The documentation provided by AngularJS has been unhelpful in resolving this issue, and most examples available online focus on setting ...

Using i18next to alter language in a React app

Implementing the i18next translation system into my React app was a breeze thanks to a helpful guide I found. However, I'm facing an issue with changing the language manually. The guide covered the setup process perfectly, but lacked information on ho ...

conceal the input once the button is clicked

Here is my code snippet: while ($row = $result->fetch_assoc()) { $id = $row['id']; ?> <script> $(document).ready(function(){ $("#btn<?echo $id?>").click(function(){ $(" ...

Emphasize identical terms in AngularJS through bold formatting

I am facing a situation where I need to apply bold formatting to specific words in an HTML string (editorData) using AngularJS, based on whether they match certain keywords (data or dataArray). It is important to note that the case of the words in editorD ...

Hiding a row in AngularJS after changing its status can be achieved by utilizing the

I need help hiding a clicked row after changing its status using angularjs. Below is the code I have written, can someone guide me on how to achieve this? table.table tr(data-ng-repeat="application in job.applications", ng-hide="application.hideApplic ...

Having difficulty retrieving the necessary information for manipulating the DOM using Express, Ajax, and Axios

When working on DOM manipulation based on AJAX calls, I've encountered an issue where the response is being displayed on my page instead of in the console.log output. This makes it difficult for me to view the data and determine what needs to be inser ...

Error: Trying to access the 'map' property of a null value, Using ReactJS with Axios

I'm currently developing a search bar feature where the user can input their query, hit the search button, and the request is stored in search. This request is then sent via Axios and the results are displayed at the end. Everything seems to be workin ...

The oninput event does not trigger if the text field value is transferred from a different form

Event Handling: The oninput event functions perfectly when I input a mobile number into the small text field in my form. It displays a message indicating that the number already exists and disables the submit button accordingly. However, it fails to valida ...

Assisting in AJAX with Rails API

My Rails website functions normally, but on certain pages I require the use of AJAX. I have successfully implemented AJAX Javascript code using jQuery without the assistance of rails helpers by manually writing corresponding paths in strings. However, I ...

Leveraging the HTML Select element for language switching on a diverse website with multiple languages

Prior to this, I had a simple website where users could switch between English and Dutch by clicking on a hyperlink. I had separate files, de.php and en.php, with language arrays like this: de.php <?php $lang = array( "title" => &quo ...

What's the deal with $routeProvider in angularJS?

I'm having some trouble with my simple web app that I'm trying to update using route provider. Everything works fine when I click on the list items on the page, but when I refresh the page, I get a 404 error. It seems like it's trying to acc ...

Learn how to create simple animations in Three.JS with just a single key press

Is it possible to make a cube move smoothly in a certain direction with just one key press? I've only been able to create continuous animation while the key is held down. Below is the code snippet I am currently working with: <script> func ...