1

i want to show my relationship values inside my result array. my results looks like this.

 "counciler": [
        {
            "id": 1,
            "name": "family",
            "description": "test description here",
            "created_at": "2020-04-16T07:57:31.000000Z",
            "updated_at": "2020-04-16T07:57:31.000000Z",
            "deleted_at": null,
            "users": [
                {
                    "id": 8,
                    "name": "stack change",
                    "email": "[email protected]",
                    "phone": "000000000",
                    "profile_image": null,
                    "address": null,
                    "user_type": "counciler",
                    "email_verified_at": null,
                    "created_at": "2020-04-16T13:32:51.000000Z",
                    "updated_at": "2020-04-16T13:32:51.000000Z",
                    "deleted_at": null,
                    "pivot": {
                        "category_id": 1,
                        "user_id": 8
                    }
                }                
            ]
        }
    ]

my question is i want to get my users array details into a v-for for list all my users in that category. how can i achieve this one?

i also tried this one but not working

<div v-for="user in counciler.users" :key="user.id"></div>
1
  • counciler is an array, so you will have to v-for over it before looping over the users Commented Apr 16, 2020 at 20:21

2 Answers 2

3

First you should iterate over the counciler array and then loop through the users items :

<template v-for="counc in counciler"
    <div v-for="user in counc.users" :key="user.id"></div>

</template>
Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome, the <template> that i used is not the root element
2

You try to access the object counciler.users but this doesn't exist because counciler is an array, not an object. Either you need to loop over counciler then other the users. Or just select the first object like so: counciler[0].users

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.