Utilizing nested JSON arrays within AngularJS for complex data structures

I'm a beginner in working with Angular and JSON, so any help would be greatly appreciated.

I have a JSON array that contains information about users and the sellers from whom they have made purchases.

JSON:

[
  {
    "name":"Kakaro",
    "sallers":[
     {"sellername":"Naruto","payment":"250","date":"07\/07\/2014","receipt":"popup"},
     {"sellername":"Sasuka","payment":"502","date":"08\/07\/2014","receipt":"popup"}
    ]
  },
  {
    "name":"Collin Ferall",
    "sallers":[
      {"sellername":"Jonny deep","payment":"250","date":"07\/07\/2014","receipt":"popup"},
      {"sellername":"Brad Pitt","payment":"502","date":"08\/07\/2014","receipt":"popup"}
    ]
  }
]

What I'm trying to accomplish: I want to display the data of a user's sellers in a table when the user is selected.

I've tried several solutions, but so far, none have worked. I find myself back at square one.

Problem: I'm struggling to correctly access an array within another array in Angular.

HTML:

<div id="main" class="row" ng-controller='payment'>
  <div>
    <label>Client Name:</label><br/>
    <select class="form-control input-sm" name="client_name">
      <option ng-repeat="names in name" value="{{names.name}}" ng-model="select">{{names.name}}</option>
    </select>
  </div>
  <div id="seller" class="margins_top">
    <table class="table table-bordered">
      <thead>
        <tr>
          <td>Seller Name</td>
          <td>Payment</td>
          <td>Date</td>
          <td>Payment Receipt</td>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="sellers in seller">
          <td>{{sellers.sellername}}</td>
          <td>{{sellers.payment}}</td>
          <td>{{sellers.date}}</td>
          <td>{{sellers.receipt}}</td>
        </tr>
      </tbody>
    </table>
  </div><!-- /#seller -->
</div>  

Controller js:

var app = angular.module('payment', []);


app.controller('payment',function($scope,$http){
  getrecord(); // Load all available tasks 
  function getrecord(){  
    $http.post("angular/ajax/payment.php").success(function(data){
      $scope.name = data;
      $scope.seller = data[0].sallers;
    });
  }
});

I created a Fiddle but it didn't help much. Here's the link to it:

Fiddle

Answer №1

Give this a shot

Insert this in your HTML

    <select class="form-control input-sm" name="customer_name" ng-model="select">
  <option ng-repeat="names in customers" value="{{names.name}}">  {{names.name}}</option>
</select>

and in your JavaScript

$scope.$watch('select', function(updatedValue) {
            angular.forEach($scope.customers, function(val, key) {
                if(val.name == updatedValue) {
                $scope.client = val.clients;
                }
            });
            });

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

Deciphering the occurrence of jQuery-Mobile page firing events: the mystery behind dialog pages appearing upon closure

I'm still fairly new to jQuery-Mobile and I'm trying to wrap my head around what exactly happens when a page or dialog is loaded. To help illustrate the confusion I'm experiencing, I put together a small collection of files that showcase th ...

Comparing object variables within Javascript's HTMLCollection

let var1, var2; // Obtaining elements from the HTMLCollection var1 = document.forms[0]; var2 = document.forms.item(0); alert(var1 === var2); // Output: "true" var1 = document.forms["myForm"]; var2 = document.forms.namedItem("myForm"); alert(var1 === v ...

Exploring the use of a customizable decorator in Typescript for improved typing

Currently, I am in the process of creating TypeScript typings for a JavaScript library. One specific requirement is to define an optional callable decorator: @model class User {} @model() class User {} @model('User') class User {} I attempted ...

Efficiently process and handle the responses from Promise.all for every API call, then save the retrieved data

Currently, I am passing three API calls to Promise.all. Each API call requires a separate error handler and data storage in its own corresponding object. If I pass test4 to Promise.all, how can I automatically generate its own error and store the data in ...

Creating a dynamic category menu using angularJS

I'm struggling with the logic behind creating a category menu using AngularJS I need to display all categories with a parent category id of 0. Once that is done, I want to display all subcategories that belong to each parent category. The final categ ...

Deciphering Complex JSON Strings with Java

I am facing a challenge with a complex String structure that resembles the following, "data":"[ { "id": "123456", "from": { "name": "ABC", "id": "123" }, "m ...

What methods can be used to update a webpage with HTML content retrieved from a Rest API using AngularJS and NodeJS?

We are currently working on a decoupled AngularJS (1.8) application with Node.JS serving it, and we are exploring options for enabling server-side rendering of a view. Within Node (included as a route with HTML response): if (req.query.username) { / ...

Building a Dynamic Web App with PHP and Vue.js

I developed an API using PHP and you can access it through this link: However, I encountered an issue when trying to display the data on the front-end of my Vue.js (Home.vue) file using axios. Below is the code I used: <ul class="ta-track-list" v-if= ...

The HTML embed element is utilized to display multimedia content within a webpage, encompassing

Currently, I am working on a static website for my Computer Networks course. Students need to be able to download homework files in PDF format from the website. I have used embed tags to display the files online, but I'm facing an issue where the embe ...

Guide on integrating angular-schema-form into an Ionic 2.0 project using typescript

Recently, I embarked on creating an app with Ionic from scratch and decided to integrate the framework. While I faced no issues executing the example on a webpage, I encountered difficulties when attempting to do so with Ionic. To kickstart the project, ...

Python: The `json.dumps()` imported string is not being recognized by the if statement, what could be the reason behind

I am fairly new to this and I am trying to parse a JSON file using a keyword to stop at the last entry. The issue is that the keyword end is not being recognized by an if statement when used with json.dumps(), so the loop never breaks. Why could this be ...

What is the best approach for rendering HTML on a page both initially and dynamically as it is updated, given the heavy utilization of ajax?

One challenge faced by many web applications today is how to efficiently reuse html templates without redundancy when initially rendering a page and adding new content. What is the most effective approach for this? One option is to render the HTML page ...

Retrieving the value of a radio button using jQuery and Ajax

Looking for assistance with radio buttons... <input type="radio" id="flip" name="flip" value="Head" checked="checked" /> Head <input type="radio" id="flip" name="flip" value="Tail" /> Tail I'm attempting to process a form with ajax, try ...

Execute a multer request to upload an image (using javascript and express)

I am utilizing the Express server as an API gateway for my microservices, specifically to process and store images in a database. The issue at hand is that within the Express server, I need to forward an image received through a POST request from the clien ...

Binding an array of objects to a class in a C# application's app settings

In my appsettings.js file, I have the following section: "AccessKeys": { "user1": { "pass": "" }, To bind this section to classes in C#, I created the following classes: public class AccessKeys { pub ...

Oops! An error has occurred: The requested method 'val' cannot be called on an undefined object

I am struggling with this issue. This is the code that I am currently working on: http://jsfiddle.net/arunpjohny/Jfdbz/ $(function () { var lastQuery = null, lastResult = null, // new! autocomplete, processLocation = function ...

I'm encountering a type error stating that children are not defined when attempting to establish parent-child relationships from a flat array. What

Trying to establish a parent-child relationship between modules based on their IDs. Ran into an issue with the function I used, as it returned an error stating that children were not defined. const data = [ { module_id: "96ac027b-b5ce-4326-b5db- ...

Instead of using onload, activate function upon click instead

Upon page load, I have a function that executes: function loadData(page){ showLoading(); $.ajax({ type: "GET", url: "load_data.php", data: "page="+page, success: function(msg) { ...

The validation for the start and end dates in the datepicker is not functioning properly when

I have integrated a bootstrap date picker into my website. However, I am encountering an issue where the end date validation does not update when I change the start date after the initial selection. <script type="text/javascript" src="htt ...

Is it possible to create an index.html page with all the necessary head tags to prevent duplicate code across multiple html pages?

Imagine I am using app.js or a Bootstrap CDN link for all of my HTML pages, but I don't want to include it in every single page individually. Is there a way to create an index.html file that includes this so that all other HTML pages load the head fro ...