3

I have some data that I'm passing to an html table:

<tr v-for="room in rooms">
      <td>{{room.name}}</td>
      <td>{{room.owner}}</td>
      <td>{{room.id}}</td>
      <td><button @click="joinChatSession" class="btn btn-primary">Join</button></td>
</tr>

I'm getting this data from an API. And I have a function joinChatSession, so my question is, how to pass this room.id to this function? I'm struggling with this once because I don't know how to access room.id for every room in my table.

My function looks like this:

$.ajax({
      url: `http://localhost:8000/api/rooms/${uri}/`,
      data: {username: this.username},
      type: 'PATCH',
      success: (data) => {
        const user = data.members.find((member) => member.username === this.username)
      }
    })

So I need to pass my room.id instead of this ${uri}, how can I access it?

1 Answer 1

4

Just pass the room.id as parameter.

<td><button @click="joinChatSession(room.id)" class="btn btn-primary">Join</button></td>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is exactly what I've been looking for! I'll be able to accept this answer in 8 minutes.

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.