Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

boyjarv's avatar

IF ELSE - Vue 3

There are notes for this contact:

"notes": [ { "id": 1, "note": "this is a test note" }, { "id": 2, "note": "Here is another note" } ]

but it's displaying: There are no notes associated with Mr Test

<div v-if="contactDetails.notes > 1">
          <ul>
            <li v-for="notesList in contactDetails.notes" :key="notesList.id">
              {{ notesList.note }}
            </li>
          </ul>
        </div>
        <div v-else>There are no notes associated with {{ fullName }}</div>
0 likes
5 replies
Sinnbeck's avatar

Like this

<div v-if="contactDetails.notes.length > 1"> 
boyjarv's avatar

@Sinnbeck No, I've tried that and I get: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')

Sinnbeck's avatar

@boyjarv so it seems that it either isn't under contactDetails or its not set? Hard to see based on the provided code

boyjarv's avatar

@Sinnbeck I really done't understand because this is showing notes:

<div v-if="contactDetails.notes" class="md:w-1/3">
          <ul>
            <li v-for="notesList in contactDetails.notes" :key="notesList.id">
              {{ notesList.note }}
            </li>
          </ul>
        </div>
        <div v-else>There are no notes associated with {{ fullName }}</div>

response from contactDetails is:

{ "id": 2, "first_name": "Esmeralda", "last_name": "Satterfield", "email": "[email protected]", "phone": "+16782828075", "address": "Apt. 287", "town_city": "North Cornell", "region_county": "Montana", "country_code": "UK", "post_code": "18646", "notes": [ { "id": 3, "note": "Here is a note for Esmeralda" } ] }
Sinnbeck's avatar

@boyjarv so it might not be set at once if it is populated by ajax?

<div v-if="contactDetails.notes && contactDetails.notes.length > 1"> 

Please or to participate in this conversation.