Creating a comparison display using ng-repeat

I have a JSON file that contains revision and history information about a modified entity, including its old and new values. The diff is generated using the jsondiffpatch library and I have parsed it further to create the final JSON format for rendering.

Here is an example of the data:

[
  {
    "createdBy": "admin@localhost",
    "modifiedAt": 1445113889873,
    "left": [
      {
        "Status": "Open"
      }
    ],
    "right": [
      {
        "Status": "In Progress"
      }
    ]
  },
  {
    "createdBy": "admin@localhost",
    "modifiedAt": 1445114315786,
    "left": [
      {
        "Description": "hello"
      },
      {
        "Assignee": "Uncle Bob (test@test)"
      }
    ],
    "right": [
      {
        "Description": "bye"
      },
      {
        "Assignee": "Willy Wonka (willy@hello)"
      }
    ]
  }
]

I am trying to find a good way to display this data in a table where each revision has separate columns for the left and right values displayed on different rows. I'm having trouble figuring out how to use ng-repeat for this:

<div ng-repeat="(key, value) in vm.revisions | orderBy:'-modifiedAt'">
      <table class="table">
        <thead>
        <tr>
          <th width="20%">Field</th>
          <th width="40%">Old Value</th>
          <th width="40%">New Value</th>
        </tr>
        </thead>
        <tbody>
        <tr>
          <td></td>
          <td></td>
          <td></td>
        </tr>
        </tbody>
      </table>
    </div>

I hope the result will look something like this:

https://i.sstatic.net/arYvd.png

Thank you in advance!

Answer №1

If my assumptions about the data format are correct:

<div ng-repeat="revision in vm.revisions | orderBy:'-modifiedAt'">
  <table class="table">
    <thead>
      <tr>
        <th width="20%">Field</th>
        <th width="40%">Old Value</th>
        <th width="40%">New Value</th>
      </tr>
    </thead>
    <tbody ng-repeat="(index, left) in revision.left">
      <tr ng-repeat="(field, leftValue) in left">
        <td>{{field}}</td>
        <td>{{leftValue}}</td>
        <td>{{revision.right[index][field]}}</td>
      </tr>
    </tbody>
  </table>
</div>

Check out a demonstration on jsfiddle: http://jsfiddle.net/q6zqgfr8/

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

Navigating in React: How to Implement the Same Route for Different Scenarios Without Compromising Your Application

I'm facing a frustrating issue while trying to incorporate Redux state management and React Router. Despite searching extensively online, I can't seem to find a solution. My Redux state, named user, stores the details of a logged-in user. Upon l ...

Step-by-step guide on adding data to an arraylist using JavaScript

My ajax callback function receives a json object (arraylist parsed into json in another servlet) as a response, and then iterates through it. Ajax section: $.ajax({ url:'ServiceToFetchDocType', data: {" ...

There seems to be an issue with the React 15 setState function not working on

My react setState after action isn't functioning properly. handleChange = () => { this.setState({foo: 'bar'}); < - it's working console.log('hellow') < - not working, console is clean } I have double-check ...

Unable to establish connection with nodejs server from external devices

Currently, I am leveraging a React client along with a Node.js server (MERN Stack). The server operates smoothly on my computer; however, I encounter difficulties when attempting to connect from my mobile phone to the IPv4 of my PC using the correct port ...

Stop Stripe checkout if all other fields are left empty

I am working on a simple "booking" function using stripe and I encountered this issue. Below is my form code: <form id="formid" action="/checkout" method="POST"> <input type="text" name="kurtuma" id="zaza"> <script src="//check ...

Utilizing Json Deserialization to Generate Replicated Objects

Instead of trying to explain the problem, it's easier to show a mock-up. internal class Program { private static void Main(string[] args) { Class1 class1 = new Class1() { Name = "Scott" }; Class2 class2 = new Class2() { Name = ...

Utilizing transitions to control the visibility of div elements

This is what I have achieved so far: function getOffsetRect(elem) { var box = elem.getBoundingClientRect() var body = document.body var docElem = document.documentElement var scrollTop = window.pageYOffset || docElem.scrollTop || body.sc ...

Steps to include an element in a JSON file stored on a remote server

One of my tasks involves working with a file called services.json located on a remote machine. [ { "kind": "SpecialService", "type": "attribute", "spec": { "addresses": [ "172.21.3.196:6379" ] }, "apiVersion": "rb ...

Utilizing post variables instead of JSON for syncing in Backbone.js

I am a beginner with backbone and currently working on creating an html5 front end for a large existing REST back end. I have encountered an issue where backbone sends the model as JSON by default when saving, but my API does not support this format. Is ...

Displaying two div elements horizontally using Material-UI

Can the styled utility from mui be used to align 2 divs side by side? The documentation examples don't seem to cover this specific scenario. While answers on this and this address it, they don't relate to mui / material ui. I attempted the fol ...

Exploring AngularJS: How can we efficiently organize sidebars and sub-pages using a modular approach?

I'm currently working on a fun and practice app where there is a dashboard module that contains other modules. I chose to structure it this way because the dashboard serves as the parent state for all the modules within it, and it didn't feel rig ...

Using TypeScript, pass an image as a prop in a Styled Component

I am facing an issue with the code below that is supposed to display the "NoBillsLaptopPNG.src" image on the screen, but for some reason, the image is not showing up. The images are being imported correctly, so I'm unsure why the image is not appeari ...

Guide on iterating through a JsonObject using Gson

Consider the following JsonObject: JsonObject jsonObject = {"keyInt":2,"keyString":"val1","id":"0123456"} Each JsonObject contains an "id" entry, but the number of other key/value pairs is variable. To address this, I aim to create an object with 2 attri ...

What is the best way to obtain clear HTTP request data in a component?

My service retrieves JSON data from the backend: constructor(private http: Http) { }; getUsers(): Observable<any> { return this.http.get('http://127.0.0.1:8000/app_todo2/users_list'); }; In the component, this data is processed: ng ...

Tips for structuring an object map with flow type to ensure that each value includes a corresponding key

In an attempt to correctly type (using Flow) a helper function called createReducer for Redux, I have utilized the code from redux-immutablejs as my starting point. I am following the recommendations from the flow documentation on typing Redux reducers, b ...

When attempting to retry in Next.js, the props obtained from getServerSideProps may

Currently, I am facing an issue with sending axios requests in getServerSideProps and passing the value through props via SSR to the client. The challenge lies in including a token in the header using an instance. In case the token expires, I utilize refre ...

Is caching a feature in AngularJS, and are there methods available for disabling it?

var modalInstance = $modal.open({ templateUrl: '/template/edit-modal.html', controller: ModalInstanceCtrl2, resolve: { locations: function () { return locationToEdit; } }, scope: $scope.$new() }); ...

Issue with Navigation Scrolling Feature on Wordpress

I am in the process of implementing a 'scroll-nav' for my website. To achieve this, I decided to separate the Navigation into two sections and incorporate some jQuery: <nav class="main-nav clearfix"> <?php wp_nav_menu(array('th ...

Sort an array of objects by matching string properties with elements from another array

If the array of objects is represented by rows and wantedBrands consists of an array of strings, how can I achieve a specific result? let rows = [ { name: "Russia", brands: ['XM1', 'XM2', 'XM3'] }, ...

Vue.js parent component not receiving data emitted by child component

Below you will find the child and parent components. I am struggling to pass data from the child component to the parent component. Can you help me pinpoint where the issue may be? Child Component <template> <div> <v-btn class="r ...