Troubleshooting data binding issues with bootstrap tab panes and accordion components

Initially, I set up a bootstrap accordion that generates panels based on items with the property "gebieden". This functionality is functioning correctly.

Within each panel, I implemented bootstrap 'tabs'. For every object with properties "onderwerpen" and "gebieden" matching those of the parent panel, a tab-pane is created. This feature is also working as expected.

However, the issue arises when it comes to displaying data inside each tab pane in a table format. Instead of showing only the data corresponding to the selected tab and panel, the table displays all key-value pairs found in the entire JSON file.

It's important to note that I am unable to modify the JSON file as it is sourced from an open dataset available at this URL: .


To demonstrate the problem succinctly, here is a snippet of my Angular code along with a portion of the hardcoded JSON data:

    var myApp = angular.module('myApp', ['ui.directives', 'ui.filters']);

function TodoCtrl($scope) {
  $scope.All = [{
    // JSON data entries here...
  }];

  $scope.selectedOnderwerpen = '';
  $scope.setOnderwerpen = function(onderwerpen) {
    console.log(onderwerpen);
    $scope.selectedOnderwerpen = onderwerpen;
  }
}

Below is my implementation using HTML and Bootstrap:

<div class="panel-group" id="accordion">
                        <div class="panel panel-default" ng-repeat="item in All | unique:'gebieden'">
                            <div class="panel-heading text-center" data-toggle="collapse" data-parent="#accordion" id="{{item.gebieden}}" href="#{{$index}}" ng-click="setGebied(item.gebieden)">
                                <h4 class="panel-title">
                                    {{item.gebieden}}
                                </h4>
                            </div>
                            <div id="{{$index}}" class="panel-collapse collapse ">
                                <div class="panel-body text-center">
                                    <ul class="nav nav-tabs">
                                        <li ng-repeat="sub in All | unique:'onderwerpen'">
                                            <a data-toggle="tab" ng-click="setOnderwerpen(sub.onderwerpen)">
                                                {{sub.onderwerpen}}
                                            </a>

                                        </li>
                                    </ul>


                                    <div class="tab-content" style="padding:2%">
                                        <div id="{{item.onderwerpen}}" class="tab-pane fade in active">
                                            <table ng-show="selectedOnderwerpen!=''" class="table table-bordered text-center">
                                                <thead>
                                                    <tr>
                                                        <th class="text-center">Year</th>
                                                        <th class="text-center">Value</th>
                                                    </tr>
                                                </thead>
                                                <tbody ng-repeat="item in All | filter:{onderwerpen:selectedOnderwerpen}:true">
                                                    <tr ng-repeat="(key,value) in item" ng-hide="$index <2">
                                                        <td>{{key}}</td>
                                                        <td>{{value}}</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

To test and debug the code effectively, I have created a demo on JSFiddle.

Answer №1

I made improvements to your code using this fiddle link. To target a specific region in the tbody, you need to add an additional filter. Without specifying the region, it defaults to targeting both 'gebieden'. Check out the updated fiddle here: http://jsfiddle.net/uwpjk28w/30/

This solution works by setting up a function that captures the region when a region tab is clicked and stores it in a variable.

Modifications:

HTML

<h4 class="panel-title" ng-click="setRegio(item.gebieden)">
        {{item.gebieden}}
   </h4>

  <tbody ng-repeat="item in All | filter:{gebieden:regio}:true | filter:{onderwerpen:selectedOnderwerpe`n}:true">

JS

$scope.selectedOnderwerpen = '';
$scope.regio = '';
$scope.setOnderwerpen = function(onderwerpen) {
    console.log(onderwerpen);
    $scope.selectedOnderwerpen = onderwerpen;
}
$scope.setRegio = function(regio) {
    console.log(regio);
    $scope.regio = regio;
}

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

Toastr - encountering a problem with the settings

After invoking a toastr message using the following command: Command: toastr["success"]("foo") toastr.options = { "closeButton": false, "debug": false, "newestOnTop": false, "progressBar": false, "positionClass": "toast-bottom-right", "prev ...

Using trackBy in conjunction with the async pipe

Attempting to utilize the async pipe along with *ngFor to exhibit an array of items obtained asynchronously. <ul> <li *ngFor="let item of items | async; trackBy: trackPost"> {{item.text}} </li> </ul> ngOnInit() { // a si ...

Understanding how objects are created using the reduce method

I'm curious about how the reduce function can transform an array into an object as shown in this example, particularly with the line: p[c[0]] = c[1]; Is this an unconventional syntax for creating key-value pairs that I haven't encountered before ...

Populate a table using the selected options from a dropdown menu, using Ajax

I'm trying to display data on my page that I fetch from a MySQL database using Ajax. I have 3 select elements in my view that provide the query information, along with a button to execute the action. However, when I click the button, nothing is displa ...

Lazy loading images without the need to manually adjust the image structure

After experimenting with various LazyLoad options, I found that most of them required modifications to the src tag or the addition of a new tag. Is there a way to LazyLoad content without having to change the tag structure? I am extracting content fro ...

Testing AngularJS components on a unit level

module.js import file from './app-image-uploader-dialog.html'; class ImageUploaderDialogController { constructor() { 'ngInject'; this.name = 'appImageUploaderDialog'; } closeWindow() { this.dismiss({ $valu ...

changing the vertical position of an element using JavaScript

I'm currently working on a project where I have a canvas that animates upwards when a button is clicked. However, I'm facing an issue with making it go back down after the animation completes. It seems to be getting stuck and not returning to its ...

Ways to include a date within a JSON object in an HTML element

Inside a meta tag attribute, I have JSON: <head> <title>PLD Interaction pattern</title> <meta data-pageObject='{ "page": { "pageInfo": { "pageID": "12345", "pageName": "smartphones:samsun ...

Issue with conditional image source URL in NUXT component not functioning as expected

I am currently attempting to dynamically render an image source path based on the provided prop in the component. In case the image does not exist in the assets folder, I want to include a fallback path. Below is the code snippet for my image tag: <img ...

What is the best way to transfer data between different states in ReactJS components?

I am in the process of developing an application that will showcase a list of categories. Upon selecting a category, the application will transition to the next page where a query regarding water type will be posed. Once the water type is chosen, the app s ...

What steps can I take to prevent drawing on the HTML5 Canvas?

I am working on creating a Paint-like application using HTML 5 Canvas. In this project, I need to implement two types of rectangles: filled and unfilled. Here is the code snippet for achieving this functionality: function drawRectangle(isFilled = false) { ...

Caution when using a React form: Value of `true` has been detected for a non-boolean attribute `validate`

I am trying to address a warning message that I have received index.js:1 Warning: Received true for a non-boolean attribute validate. If you want to write it to the DOM, pass a string instead: validate="true" or validate={value.toString()}. I ...

Utilizing AJAX with a combination of JSON and HTML data types

I recently completed a tutorial on ajax and implemented a script that retrieves JSON data and appends it to a table. $.ajax({ url: 'insert.php', type: 'POST', data: {data1: name, data2: phone, data3: address}, dataTyp ...

The dimensions of the sprites within Three.js geometry

I am interested in creating an animation of sprites moving along a figure, particularly sprites that walk along the figure. An example of what I envision can be seen here: http://armsglobe.chromeexperiments.com/ I found some helpful information related t ...

The MongoDB search results did not yield the desired entries

i am attempting to display specific data for a user using req.session.user and passing the ID to the criteria i am constructing. (each entry also has a user field so i can match) but unfortunately, it is not functioning as expected. The Service : async fu ...

Ways to display the page's content within a div container utilizing Jquery

I am attempting to display the content of a URL page (such as ) within a <div> using JQuery, but so far I have been unsuccessful. Here is an example of what I am trying to achieve: <div id="contUrl"> .. content of google.fr page </div> ...

Identify alterations in an input field after selecting a value from a dropdown menu

Is there a way to detect changes in the input field when selecting a value from a drop-down menu, similar to the setup shown in the image below? html: <input type="text" class="AgeChangeInput" id="range"/> js:(not working) <script> $(docume ...

Issue: Module './' could not be located

Encountered this error while trying to launch my application using NPM start. Strangely, it worked perfectly on another computer. I unzipped the file, ran npm install, and attempted to start the app, only to be hit with the following error: Any assistance ...

What is the proper way to retrieve items from an Array that have an index that is evenly divisible by

let numbers = [4, 5, 7, 8, 14, 45, 76]; function getEvenElements(arr) { let evenArray = []; for (let i = 0; i < arr.length / 2; i++) { evenArray.push(arr[2 * i]); } return evenArray.filter(num => num !== undefined); } alert(getEvenEle ...

Retrieve data from a template's php variables using ajax

Although I have tried looking for solutions in other forums, I am still facing issues with a particular question that I cannot seem to resolve. My situation involves calling a template via ajax which sets some PHP variables inside it, and I am struggling ...