0

In my vuejs project I have an empty "CatalogItems" array. Thanks to a method I push data into this array, and when I do

console.log(this.catalogItems)

We see that my table contains 30 objects.

These objects contain several attributes (id, locale, ..), and among these attributes there is an object named "configuation" which contains the attribute "format".

enter image description here

On my front I have a loop with a v-for, its purpose is to display the different attributes of each object in my "CatalogItems" array.

<tr v-for="data in catalogItems" :key="data.value">
    <td>{{ data.id }}</td>
    <td>{{ data.name }}</td>
    <td>{{ data.locale }}</td>
    <td>{{ data.configuration }}</td>
    <td>{{ data.date }} <br> {{ data.heure }}</td>
    <td class="sousMenuTable flex justifyContentBetween">
      <span class="flex alignItemsCenter justifyContentCenter">{{ data.nombreDetecte }}</span>
      <span class="flex alignItemsCenter justifyContentCenter">{{ data.nombreInsere }}</span>
      <span class="flex alignItemsCenter justifyContentCenter">{{ data.nombreRejete }}</span>
    </td>
    <td>{{ data.type }}</td>
    <td>{{ data.load_frequency }}</td>
    <td class="marginRight15">
      <div class="ti-pencil flex justifyContentCenter alignItemsCenter"></div>
    </td>
    <td>
      <div class="switchOnOff flex alignItemsCenter" :data-etat="data.etat" @click="switchStatus">
        <div class="circle"></div>
        <span class="bold uppercase">{{ data.etat }}</span>
      </div>
    </td>
  </tr>

My problem is that on my front end I can't display the "format" attribute of my "configuration" object present in my "CatalogItems" object array.

I tried to do this :

<td v-for="element in data.configuration">
  {{ element.format }}
</td>

But I have no visible results (nor any errors)

5
  • I don't see the element.format in the console.log result. That key exists in all the objects? Also, you could set up a reproducible example using vue playground - sfc.vuejs.org. Now you know it for next times (: Commented Sep 19, 2022 at 11:12
  • Yes sorry ! I update it Commented Sep 19, 2022 at 11:39
  • So seems in some objects format is defined and in other ones it isn't, right? Commented Sep 19, 2022 at 11:40
  • I'm not sure... in the console.log I see a value for format or maybe I don't understand Commented Sep 19, 2022 at 11:52
  • You have to be sure. Check it. Also, as said, if you set up a reproducible example + vue playground, ppl will help you more easily. also, provide some input examples and your expected outputs Commented Sep 19, 2022 at 11:55

3 Answers 3

1

data.configuration looks like an object and not an array.

you should try to replace

<td v-for="element in data.configuration">
  {{ element.format }}
</td>

by

<td>
  {{ data.configuration.format }}
</td>
Sign up to request clarification or add additional context in comments.

Comments

1

You have probably an error in the last interpolation {{ element.format }} - you are accessing field format of elements of data.configuration, you should remove .format (since it's undefined). You can see working example of what you are trying to achieve in this codesandbox https://codesandbox.io/s/angry-chatterjee-nzgwuv?file=/src/App.vue

1 Comment

Thx for your answer :) I'll try but data.configuration have many attribute.. not only "format" so I have to focus the one I want
0

I can't explain why.. but! I show it to a friend, retry the same thing as I try the morning and it works..

The answer is

<td>{{ data.configuration.format }}</td>

Thanks for your answers! Have a nice day

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.