Display collection in Vue app

I am working with a model called files, which includes a property named response containing an array called errorMessages. In my Vue component, I am looking for a way to display these errors individually rather than as an array. Is there a solution for this?

    {
  "files": [
    {
      "fileObject": true,
      "size": 9387,
      "name": "file_4444.pdf",
      "type": "application/pdf",
      "active": false,
      "error": true,
      "success": true,
      "postAction": "http://localhost:8000/api/v1/car/upload",
      "timeout": 0,
      "file": {},
      "el": {
        "__vue__": null
      },
      "response": {
        "uploadDone": 0,
        "uploadFail": 1,
        "errorMessages": [
          "User not found",
          "Car not found",
        ]
      },
      "progress": "100.00",
      "speed": 9591,
      "data": {},
      "headers": {},
      "id": "096vnj6rov9t",
      "xhr": {}
    }
  ]
}

<template>
  <div class="example-drag">
    <div class="upload">
      <ul v-if="files.length">
        <li v-for="(file, index) in files" :key="file.id">
          <span>{{file.name}}</span> -
          <span v-if="file.error"> {{ file.response.errorMessages }} <md-icon>thumb_down</md-icon> </span>
          <span v-else-if="file.success">success <md-icon>thumb_up</md-icon> </span>
          <span v-else-if="file.active">active <md-icon>thumb_up</md-icon> </span>
          <span v-else>  ... </span>

        </li>
      </ul>
   ...
</template>

Answer №1

Make sure to loop through the errorMessages array

<ul v-if="files.length">
  <li v-for="(file, index) in files" :key="file.id">
    <span>{{file.name}}</span> -
    <span v-if="file.error"> 
      <ol>
       <li v-for="err in file.response.errorMessages> {{ err }} </li>
      </ol>
    </span>
  </li>
</ul>

Alternatively, you can use the .join method of the array (

['hello', 'world'].join(", ") => 'hello, world'
)

<span v-if="file.error">{{ file.response.errorMessages.join(", ") }}</span>

Answer №2

    {
  "files": [
    {
      "fileObject": true,
      "size": 7485,
      "name": "file_9999.pdf",
      "type": "application/pdf",
      "active": true,
      "error": false,
      "success": true,
      "postAction": "http://localhost:8000/api/v1/boat/upload",
      "timeout": 0,
      "file": {},
      "el": {
        "__vue__": null
      },
      "response": {
        "uploadDone": 1,
        "uploadFail": 0,
        "errorMessages": [
          "User found",
          "Boat found"
        ]
      },
      "progress": "90.50",
      "speed": 7458,
      "data": {},
      "headers": {},
      "id": "097jfn6ytpq8z",
      "xhr": {}
    }
  ]
}

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 the Coinmarketcap API currently experiencing downtime in Python?

I've been relying on the Coinmarketcap Api https://api.coinmarketcap.com/v1/ticker/ for a while now. It was a great resource providing almost real-time data (every 130s) in a convenient .json format and best of all, it was free! However, it seems lik ...

Converting string to Java objects using JSON deserialization and mapping property names to field names

When I receive JSON data from an API, it looks like this: { "channel":"masta", "startTime":1427673600000, "endTime":1427760000000, "totalUniques":1, "totalViewtime":1927, "totalViews":13, "totalCountries":1, "countries":{ "US":{ ...

I am having trouble viewing the JSON data on my activity's RecyclerView, which has been stored on a web server and accessed via a URL

When I try to run my activity, I am encountering an issue where I cannot see any JSON data from the webserver in my RecyclerView. All I see is a progress bar followed by an empty activity. I have already verified my adapter, I have set the adapter in the ...

Spring controller experienced a 404 not found error when making a jQuery AJAX call

I am new to Spring and I have generated a JSON as shown below: [ { "customer" : "16", "project" : "19", "phase" : "47", "approver" : "5", "date1" : "", "date2" : "", "date3" : "", "date4" : "", "date5" : "", "da ...

The attribute 'constructor' is not found on the 'T' type

I'm currently working on a project using Next.js and TypeScript. I've come across an issue where TypeScript is giving me the error "Property 'constructor' does not exist on type 'T'" in my generic recursive function. Here&apo ...

Sending an AJAX request will only transmit a portion of an array when using the JSON.stringify

I have a JavaScript array that is constantly updated. Here's how I initially set up the array... columnArray = ["userID", "Date", "trialType", "cue", "target", "response", "accuracy", "lenAcc", "strictAcc", "fkpl", "totalTime"]; var dataArray = []; ...

My Scope Filter isn't functioning properly; rather than filtering the data, I am just receiving the results of a plain select * from query

Currently, I am working on a small project that involves utilizing Laravel and Vuejs. Specifically, my goal is to create a basic age filter for users. After thorough testing, it appears that the issue lies within my scopeWithFilters function. When I used ...

The picture is displayed just once, despite the fact that it was supposed to be returned 50 times within the loop

I'm encountering an issue while trying to use a for loop to render an image in a React component. The loop is not functioning as expected, resulting in the image being displayed only once on the screen even though the intention is to show the same ima ...

Looking to store HTML form data in MongoDB and showcase the saved information on a webpage using AngularJS, ExpressJS, and NodeJS

Client-side : Example HTML Code <body ng-controller="myAppController"> <nav class="navbar navbar-inverse"> <div class="container-fluid"> <div class="navbar-header"> <h1>person details</h1> </div> ...

Conceal flexbox item depending on neighboring element dimensions or content

I've encountered an issue while using a flexbox to display two elements side by side. The left element contains text, while the right one holds a number. When the value in the right element has at least 7 digits ( > 999,999 or < -999,999), I ne ...

Transmitting JSON data over an HTTP request, yet receiving an empty response

I am facing an issue with sending JSONs to another application. The problem is that the receiving application keeps receiving NULL parameters. Here is the code from my "sender" app: public class Main { public static void main(String[] args) { ...

Instructions for creating a JavaScript click function that iterates through all records, not just the initial record

Although I'm new to web development and still learning the basics of html, javascript, etc., I have a problem that seems quite simple. The challenge lies in understanding javascript functions, which I find particularly tough to grasp. Here's what ...

Showcasing data from a promise in the template with Nuxt.js

When trying to show the color {{ bgColor }} in my template, I'm only getting [object Promise]. const { getColorFromURL } = require('color-thief-node') export default { data() { return { api_url: process.env.strapiBaseUri, ...

JavaScript: Modify the dropdown class with a toggle option

Hi there, I'm currently facing a small issue and I could really use some assistance. I have a dropdown menu with two selection options - "green" and "blue", and I need to toggle a class based on the selected option. If you'd like to take a look, ...

When I scroll through Datatable, not all of my rows are displayed

I am facing a challenge where I need to retrieve rows from the back-end response as I scroll. Although I receive an AJAX response, I am unable to get the full row of data; it seems that the last row gets cut off. I have attempted several alternative solut ...

Rendering implemented in an Angular component through Three.js

Currently immersed in developing a dynamically generated three.js component within Angular. The statically created Plot3dComponent (via selector) functions flawlessly. However, encountering difficulties in rendering the component dynamically using Componen ...

The @Input decorator in Angular 2/4 is designed to only transfer fundamental values and not collections or complex data

I have encountered an issue while attempting to use @Input with a list of objects, where the @Input variable ends up being undefined. What is functioning properly can be seen in home.component.html: <p> <it-easy [mycount]="countItem" (result ...

Is it possible to utilize types as constants in a switch statement?

In my file called checkoutTypes.ts, I have defined some checkout types like this: export type CheckoutInvoiceAddressSection = "InvoiceAddress"; export type CheckoutDeliveryAddressSection = "DeliveryAddress"; export type CheckoutDelivery ...

Alternative to Lodash for performing a check operation in JavaScript and assigning a new value

Recently, I've been utilizing a code snippet to verify the value of an input field located at index:1 within an array. The code looks like this: const inputValue=journeyData && journeyData.birthdate && journeyData.birthdate[0] ...

When adding elements to an array in PHP, they all appear to be identical

I'm facing an issue where pushing multiple objects into an array results in them all having the same value, even though they are supposed to have different values. How can I fix this problem? $sql="select password, mail from account"; $result=mysql_q ...